William Vaughn
7/21/2007 5:02:00 PM
Or, better yet, do the conversion on the client. It will help your query run
faster (as the SQL engine does not have to do the conversions and
concatenation).
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
www.hitchhikerguides.net
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
"JP Bless" <jp3BlessNoSpam@hotmail.com> wrote in message
news:eIyx9O7yHHA.3916@TK2MSFTNGP02.phx.gbl...
> Thanks very much... appreciate your help
>
>> NOTE: you need to define the length of the nvarchar, which is typically
>> the length of the number.
>
> What if the length of nvarchar is unknown?
>
> "D@t@Mill" <andrewrobertmiller@gmail.com> wrote in message
> news:6398A987-FEE8-4923-9127-CB5883D4C28A@microsoft.com...
>> If you want to return a numeric value concatenated with alpha data
>> implicit conversions fail. So you need to convert() or cast(), both are
>> very similar although I prefer convert as you can explicitly define the
>> full data type including the length. I've included an example below.
>>
>> SELECT convert(nvarchar(10),tbl_Employees.EmployeeNumber) +
>> tbl_Employees.FirstName As WDS
>> FROM tbl_Employees
>>
>> OR
>>
>> SELECT cast(tbl_Employees.EmployeeNumber as nvarchar) +
>> tbl_Employees.FirstName As WDS
>> FROM tbl_Employees
>>
>>
>> "JP Bless" <jp3BlessNoSpam@hotmail.com> wrote in message
>> news:%230S1Cn4yHHA.5408@TK2MSFTNGP02.phx.gbl...
>>> ssql = "SELECT tbl_Employees.EmployeeNumber + ' ' +
>>> tbl_Employees.FirstName As WDS FROM tbl_Employees"
>>>
>>> I am trying to concatenate two fields in SQL Server Express 2005.
>>> Employees number is int (Number) and Employees Firstname is
>>> varchar(String)
>>>
>>> I get the error
>>>
>>> Msg 245, Level 16, State 1, Line 1
>>>
>>> Conversion failed when converting the nvarchar value 'Jason' to data
>>> type int.
>>>
>>> Please help... Thanks very much in advance
>>>
>>>
>>>
>>>
>>
>
>