Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 append fields in select statement

Author  Topic 

Trent
Starting Member

39 Posts

Posted - 2005-11-29 : 09:52:24
I'm trying to append an int and a char field as one column in my select statement. Easy enough if their both the same data types, but I'm having trouble figuring it out when the data types are different. Here's a simplified version of what I'm trying to do:

select FirstName, cast(datediff(dd, getdate(), Birth)/365 * -1 as int) + GenderID as Demo
from tTester
Where TesterID = '91055'

And the error:

Syntax error converting the varchar value 'F' to a column of data type int.

Thanks for any help!

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-11-29 : 09:54:44
i am guessing genderid is in fact 'F'? Make the genderid a 0 or 1 (use a case statement) and then append it.

can't append a data type of int to a datatype of varchar.

________________________________________________

Drinking German Beer... fun.
Listening to an accordian player play ACDC...priceless
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-29 : 09:55:41
select FirstName, cast(datediff(dd, getdate(), Birth)/365 * -1 as varchar) + GenderID as Demo
from tTester
Where TesterID = '91055'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Trent
Starting Member

39 Posts

Posted - 2005-11-29 : 10:08:06
Thanks! That's what I get for doing this early morning programming....
Go to Top of Page
   

- Advertisement -