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
 General SQL Server Forums
 New to SQL Server Programming
 select query

Author  Topic 

esambath
Yak Posting Veteran

89 Posts

Posted - 2009-11-26 : 00:36:20
Hi,

I have one table LP_Expertation

Id IDENTITY
Name Varchar(128)
Price nvarchar(8)

Table values

Id Name Price
1 A 1
2 B 5
3 C .5
4 d 0.6

select (CASE WHEN Price = '' THEN 0 ELSE Price END) as Price from LP_Expertation

we got the following error message

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '.5' to data type int.


kindly advice this one

if you need more clarification means i will explain you

Thanks an advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-11-26 : 00:42:39
why are you storing Price in a string column ? You should use numeric or decimal data type for the Price



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-11-26 : 00:47:25
select (CASE WHEN Price = '' THEN '0' ELSE Price END) as Price from @i
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-11-26 : 00:47:38
Try this

select (CASE WHEN Price = '' THEN '0' ELSE Price END) as Price from LP_Expertation

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

esambath
Yak Posting Veteran

89 Posts

Posted - 2009-11-26 : 00:55:06
quote:
Originally posted by senthil_nagore

Try this

select (CASE WHEN Price = '' THEN '0' ELSE Price END) as Price from LP_Expertation

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/




Dear senthil_nagore,

your query is working thanks a lot
Go to Top of Page

esambath
Yak Posting Veteran

89 Posts

Posted - 2009-11-26 : 00:56:19
quote:
Originally posted by khtan

why are you storing Price in a string column ? You should use numeric or decimal data type for the Price



KH
[spoiler]Time is always against us[/spoiler]





Dear khtan,

we are maintain the lot of values its cannot easy convert another data type

thanks an advance
Go to Top of Page
   

- Advertisement -