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
 GUID as parameter

Author  Topic 

roshana
Starting Member

31 Posts

Posted - 2010-02-09 : 00:24:31
Hi all,

How we can pass GUID as a parameter in the not in statement

For eg:
delete from [Table_A] where Task not in ({'0EEB1760-A22D-4256-A9DE-867B0C72ED3D'},{'126826D6-98EE-421F-AF72-DFCFBC3F1A41'})

I am getting some syntax error in the above statement.If i use {} instead of () in the outer bracket then also i am getting the syntax error

Please help me
Thanks
Roshana

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 05:33:39
this is working for me


delete from [Table_A] where Task not in ('0EEB1760-A22D-4256-A9DE-867B0C72ED3D','126826D6-98EE-421F-AF72-DFCFBC3F1A41')
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-02-09 : 06:30:24
or

delete
from [Table_A]
where Task not in ('{0EEB1760-A22D-4256-A9DE-867B0C72ED3D}','{126826D6-98EE-421F-AF72-DFCFBC3F1A41}')



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

roshana
Starting Member

31 Posts

Posted - 2010-02-09 : 11:54:45
Thanks for your help

I thought if we use GUID in single quotes like ('0EEB1760-A22D-4256-A9DE-867B0C72ED3D') this it will treat it as a string instead of GUID

Roshana
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 11:57:04
quote:
Originally posted by roshana

Thanks for your help

I thought if we use GUID in single quotes like ('0EEB1760-A22D-4256-A9DE-867B0C72ED3D') this it will treat it as a string instead of GUID

Roshana


Ok. Have you now tried it?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-09 : 12:02:34
"I thought if we use GUID in single quotes like ('0EEB1760-A22D-4256-A9DE-867B0C72ED3D') this it will treat it as a string instead of GUID"

SQL Server will make an [implicit] CAST where it can. So:

WHERE MyGUID = '0EEB1760-A22D-4256-A9DE-867B0C72ED3D'

will first cause an implicit cast of '0EEB1760-A22D-4256-A9DE-867B0C72ED3D' to a UNIQUEIDENTIFIER and then the comparison with [MyGUID] will be performed.

You can make an explicit cast if you like:

WHERE MyGUID = CASE('0EEB1760-A22D-4256-A9DE-867B0C72ED3D' AS UNIQUEIDENTIFIER)

which avoids any ambiguity as to what SQL might do
Go to Top of Page

roshana
Starting Member

31 Posts

Posted - 2010-02-09 : 12:24:58
Visakh
I tried both and working perfectly

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 12:28:23
quote:
Originally posted by roshana

Visakh
I tried both and working perfectly

Thanks


cool
Go to Top of Page
   

- Advertisement -