August 12, 2005 at 8:01 am
Hi everyone,
I have a table with a Year column and a Month column where the year corresponds with the month.
I'm having trouble with a query though.
This is what i want to do.
SELECT Year, Month FROM table
WHERE Year AND Month Between Year AND Month
I've created a dateserial function, but this table does not have a day column.
Can anyone provide me any suggestions?
August 12, 2005 at 8:14 am
Here's the correct solution :
Select Whatever from dbo.Table where DateCol between @DateStart and @DateEnd.
Can you remerge the month/year columns into a smalldatetime column?
August 12, 2005 at 8:17 am
I cannot merge the columns because the table is being used for import in another application.
The application will reject the table if it is not in this format.
August 12, 2005 at 8:24 am
k. can you give data samples, the parameters for the where conditions and the expected results?
August 12, 2005 at 8:33 am
You should be able to merge the columns within the selection contstraint: i.e..
WHERE CONVERT( varchar, CONVERT( smalldatetime, [Month] + '/01/' + [Year]) BETWEEN '01/01/2005' AND '07/01/2005'
That should not impact the actual columns you use to pass into another application.
(btw, I used CONVERT( varchar, ....... , 101) because it displays without the timestamp. It is not actually required to make this work unless the time is of issue...).
I wasn't born stupid - I had to study.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply