Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case-When to convert VarChar to Numeric variable

Status
Not open for further replies.

devon59

Technical User
Nov 30, 2005
18
US
I'm trying to create a new variable base on existing variable, BuyerID, using case-when statement. However, the query I have doesn't work. Could anyone please help? Part of the query and error message are below.

*************************
case
when BuyerID='Null' then 1
else 0
end
as BuyerCount
**************************
**************************
Server: Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.
 
'Null' means a string that contains the letters N U L & L which is probably not what you want. You can test for null like this...

case
when BuyerID [red]Is Null[/red] then 1
else 0
end
as BuyerCount

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top