all groups > sql server programming > december 2005 >
You're in the

sql server programming

group:

Trouble using sql IN statement with list of datetimes


Trouble using sql IN statement with list of datetimes JavaJeff NO[at]SPAM gmail.com
12/29/2005 7:25:48 PM
sql server programming: I would like to pass in a list of dateTime stamps in a nVarChar
parameter like so:

--Example input data:
'2005-12-21 15:55:26.053, 2005-12-21 15:41:35.600, 2005-12-21
15:23:21.647, 2005-12-20 19:15:27.180'

declare @RequestCreationTimeList nvarchar(500)

Select dbo.MyTable.RequestCreationTime, FieldA, FieldB
where ( convert(varchar, dbo.MyTable.RequestCreationTime,21)
IN (' + @RequestCreationTimeList + ') )


I am not able to get any matches...
I have a feeling it has to do with not having quotes in between the
individual datatime stamp.

This works:

select dbo.MyTable.RequestCreationTime, convert(varChar,dbo.
MyTable.RequestCreationTime,121) as [String]

from dbo.MyTable

where (convert(varchar,dbo.MyTable.RequestCreationTime,21) =
'2005-12-21 15:55:26.053')

-- output:
2005-12-21 15:55:26.053 2005-12-21 15:55:26.053

So I'm pretty sure my formatting is correct...
If any one has any insight on this I would be most appreciative.

Thanks,

Jeff
RE: Trouble using sql IN statement with list of datetimes ML
12/30/2005 2:29:03 AM
You can't pass a delimited string inside an IN expression without preparing
the query string (i.e. without using dynamic SQL).

Try this function by Dejan Sarka:
http://solidqualitylearning.com/blogs/dejan/archive/2004/10/22/200.aspx


ML

---
Re: Trouble using sql IN statement with list of datetimes JavaJeff NO[at]SPAM gmail.com
12/30/2005 7:52:31 AM
Many thanks for the lightning fast response! =)
Re: Trouble using sql IN statement with list of datetimes ML
1/3/2006 1:21:02 AM
Don't forget to thank Dejan in his blog. :)


ML

---
AddThis Social Bookmark Button