Home All Groups Group Topic Archive Search About

sp_executesql and datetime

Author
7 Apr 2006 4:45 PM
ina
Hello all,

I have this code and I do not know why I have this error.

EXECUTE sp_executesql
    N'SELECT * FROM TABLE
    WHERE T_ID = @level and timestamp = @timestamp',
     N'@timestamp datetime',
     N'@level int',
     @level = '1' and @timestamp between '2006-03-01' and '2006-03-31';

I thank in advanced

Ina

Author
7 Apr 2006 7:38 PM
Raymond
Try this:

EXECUTE sp_executesql
N'SELECT * FROM TABLE WHERE T_ID = @level and timestamp between @timestamp
and @timestamp2',
N'@timestamp datetime, @timestamp2 datetime, @level int',
@level = '1' ,
@timestamp = '2000-11-24' ,
@timestamp2 = '2005-01-01'

--

Raymond Yap

Show quote
"ina" <roberta.inal***@gmail.com> wrote in message
news:1144428316.066769.218440@e56g2000cwe.googlegroups.com...
> Hello all,
>
> I have this code and I do not know why I have this error.
>
> EXECUTE sp_executesql
>     N'SELECT * FROM TABLE
>     WHERE T_ID = @level and timestamp = @timestamp',
>      N'@timestamp datetime',
>      N'@level int',
>      @level = '1' and @timestamp between '2006-03-01' and '2006-03-31';
>
> I thank in advanced
>
> Ina
>
Author
7 Apr 2006 9:49 PM
Arnie Rowland
You are combining an EQUALITY with a BETWEENS. It just doesn't work.

Change the code to have a Start TimeStamp range and a Stop TimeStamp range,.

--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."

*Yet Another Certification Exam


Show quote
"ina" <roberta.inal***@gmail.com> wrote in message
news:1144428316.066769.218440@e56g2000cwe.googlegroups.com...
> Hello all,
>
> I have this code and I do not know why I have this error.
>
> EXECUTE sp_executesql
>    N'SELECT * FROM TABLE
>    WHERE T_ID = @level and timestamp = @timestamp',
>     N'@timestamp datetime',
>     N'@level int',
>     @level = '1' and @timestamp between '2006-03-01' and '2006-03-31';
>
> I thank in advanced
>
> Ina
>
Author
10 Apr 2006 9:44 AM
ina
thank you very much

AddThis Social Bookmark Button