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
 Between concatination

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2011-02-04 : 07:18:37
Hello there.

i want to create a between clause for a date. BUT. I have three variables.

One for Day, one for Month and One for year.

Is there a way i can concatinate them into a between clause.

for eg date between 'variable1-variable2-variable3 AND

variable1-variable2-variable3 '

MCTS / MCITP certified

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-02-04 : 07:24:21
what are there data types?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-04 : 07:28:27
Assuming they are integers and a 4 digit year

CONVERT(varchar(8), (@YEAR*10000) + (@MO*100)+(@DAY))

you would be better to do
DATE>= CONVERT(varchar(8), (@YEAR*10000) + (@MO*100)+(@DAY))
and DATE <= CONVERT(varchar(8), (@YEAR*10000) + (@MO*100)+(@DAY))





Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-04 : 09:18:42
or

datecol>=dateadd(day,@day,dateadd(month,@month-1,dateadd(year,@year-1900,0)))
and
datecol<dateadd(day,@day,dateadd(month,@month-1,dateadd(year,@year-1900,0)))+1


Madhivanan

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

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2011-02-04 : 10:03:28
how do i select the the first day of the year, but only the day not the whole date. eg 01
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-04 : 12:04:31
If it is already a variable, just pass a 1 as the value...





Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page
   

- Advertisement -