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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Multiple 'BETWEEN' Statements

Author  Topic 

Gyto
Posting Yak Master

144 Posts

Posted - 2006-09-25 : 06:57:04
Hey

I'm having trouble with an SQL statement where I need to include multiple commands, in particular BETWEEN commands.

Example:

SELECT * FROM dbo.Table WHERE TheDate BETWEEN ("& Date1 &") AND ("& Date2 &").....Then I need to add more statements here, but I'm not sure of the syntax....assuming it's possible?!

If not will I have to split it down into multiple SQL statements?

Thanks in advance!

Matt

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-25 : 07:12:52
Somthing like this


SELECT * FROM dbo.Table WHERE (TheDate BETWEEN ("& Date1 &") AND ("& Date2 &")) And (TheDate1 BETWEEN ("& Date3 &") AND ("& Date4 &"))


Chirag
Go to Top of Page

Gyto
Posting Yak Master

144 Posts

Posted - 2006-09-25 : 08:36:18
Great thanks, think I've done it :)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-25 : 09:37:30
Don't concatenate a sql string like that, always use parameters.

see: http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx

- Jeff
Go to Top of Page
   

- Advertisement -