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
 How to pass Any datatype value in Where Statement

Author  Topic 

john20
Starting Member

30 Posts

Posted - 2009-04-08 : 08:32:33

Hi All,

I want to pass any datatype value in where statement of sql query.
for example :

Select Name from users where ID=1000

or

Select Name from users where ID='1000'

what i meant by that is i am not sure what is the data type of ID field in the customers database.It can be of any type Integer or Character.

how can i do that?

Thanks
-John






SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-08 : 08:47:02
You can always pass the parameter value as varchar, since that is a datatype almost every other datatype can be converted to.
But beware of performance problems when you pass a varchar, and the column is an INT and in that case, all values must be converted from INT to varchar.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

john20
Starting Member

30 Posts

Posted - 2009-04-08 : 09:23:59

Hi Thankd for your reply.

Can you please show me how to do that in the above case.

how to convert in to varchar.

Thanks

john

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-08 : 09:46:27
If the passed value is always a number, then it would work with/without having single quote around passed value

Madhivanan

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

john20
Starting Member

30 Posts

Posted - 2009-04-08 : 11:41:12

Thanks Madhivanan Its working now...

Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-09 : 02:17:08
quote:
Originally posted by john20


Thanks Madhivanan Its working now...

Cheers


You are welcome

Madhivanan

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

- Advertisement -