SET DATEFIRST 1
SELECT
dateCol,
CASE DATEPART(dw, dateCol)
WHEN 1 THEN 'YES
ELSE 'NO'
END AS [IsMonday]
FROM
yourTable
- Anith
Quote:> I need a query to list all dates from a certain date. I am not sure if
this
> is possible. I want this for a report that will show every monday from a
> certain date and then I will have a sub-report for the detail if there is
> any. The dates will show me the ones I do not have detail for.
sp_listalldaysfrom('1/1/2002')
1/1/2002
1/2/2002
1/3/2002
...
> SET DATEFIRST 1
> SELECT
> dateCol,
> CASE DATEPART(dw, dateCol)
> WHEN 1 THEN 'YES
> ELSE 'NO'
> END AS [IsMonday]
> FROM
> yourTable
> - Anith
> > I need a query to list all dates from a certain date. I am not sure if
> this
> > is possible. I want this for a report that will show every monday from
a
> > certain date and then I will have a sub-report for the detail if there
is
> > any. The dates will show me the ones I do not have detail for.
SET DATEFIRST 1
BEGIN
SELECT
WHEN 1 THEN 'YES'
ELSE 'NO' END AS [IsMonday]
END
Or if you need to use them in JOINs , create a #temp
table
SET DATEFIRST 1
CREATE TABLE #Temp(testDate DATETIME)
BEGIN
END
SELECT
testDate,
CASE DATEPART(dw, testDate)
WHEN 1 THEN 'YES'
ELSE 'NO' END AS [IsMonday]
FROM
#Temp
- Anith
> sp_listalldaysfrom('1/1/2002')
> 1/1/2002
> 1/2/2002
> 1/3/2002
> ...
> > Something like this?
> > SET DATEFIRST 1
> > SELECT
> > dateCol,
> > CASE DATEPART(dw, dateCol)
> > WHEN 1 THEN 'YES
> > ELSE 'NO'
> > END AS [IsMonday]
> > FROM
> > yourTable
> > - Anith
> > > I need a query to list all dates from a certain date. I am not sure
if
> > this
> > > is possible. I want this for a report that will show every monday
from
> a
> > > certain date and then I will have a sub-report for the detail if there
> is
> > > any. The dates will show me the ones I do not have detail for.
declare tempTable with one date column
insert into tempTable startdate
while startdate < end date
set startdate = startdate + 1
insert into tempTable startdate
end
select * from tempTable
I need a coffee.
> SET DATEFIRST 1
> BEGIN
> SELECT
> WHEN 1 THEN 'YES'
> ELSE 'NO' END AS [IsMonday]
> END
> Or if you need to use them in JOINs , create a #temp
> table
> SET DATEFIRST 1
> CREATE TABLE #Temp(testDate DATETIME)
> BEGIN
> END
> SELECT
> testDate,
> CASE DATEPART(dw, testDate)
> WHEN 1 THEN 'YES'
> ELSE 'NO' END AS [IsMonday]
> FROM
> #Temp
> - Anith
- Anith
> I need a coffee.
> > How about...
> > SET DATEFIRST 1
> > BEGIN
> > SELECT
> > WHEN 1 THEN 'YES'
> > ELSE 'NO' END AS [IsMonday]
> > END
> > Or if you need to use them in JOINs , create a #temp
> > table
> > SET DATEFIRST 1
> > CREATE TABLE #Temp(testDate DATETIME)
> > BEGIN
> > END
> > SELECT
> > testDate,
> > CASE DATEPART(dw, testDate)
> > WHEN 1 THEN 'YES'
> > ELSE 'NO' END AS [IsMonday]
> > FROM
> > #Temp
> > - Anith
Thanks for your help.
> - Anith
> > I guess I got lazy when I answered.
> > And sorry, I missed the Monday part of the question.
> > I need a coffee.
> > > How about...
> > > SET DATEFIRST 1
> > > BEGIN
> > > SELECT
> > > WHEN 1 THEN 'YES'
> > > ELSE 'NO' END AS [IsMonday]
> > > END
> > > Or if you need to use them in JOINs , create a #temp
> > > table
> > > SET DATEFIRST 1
> > > CREATE TABLE #Temp(testDate DATETIME)
> > > BEGIN
> > > END
> > > SELECT
> > > testDate,
> > > CASE DATEPART(dw, testDate)
> > > WHEN 1 THEN 'YES'
> > > ELSE 'NO' END AS [IsMonday]
> > > FROM
> > > #Temp
> > > - Anith
begin
begin
end
end
> Thanks for your help.
> > Cheer up! It happens to me all the time
> > "HAVE COFFEE, BE HAPPY" :-)
> > - Anith
> > > I guess I got lazy when I answered.
> > > And sorry, I missed the Monday part of the question.
> > > I need a coffee.
> > > > How about...
> > > > SET DATEFIRST 1
> > > > BEGIN
> > > > SELECT
> > > > WHEN 1 THEN 'YES'
> > > > ELSE 'NO' END AS [IsMonday]
> > > > END
> > > > Or if you need to use them in JOINs , create a #temp
> > > > table
> > > > SET DATEFIRST 1
> > > > CREATE TABLE #Temp(testDate DATETIME)
> > > > BEGIN
> > > > END
> > > > SELECT
> > > > testDate,
> > > > CASE DATEPART(dw, testDate)
> > > > WHEN 1 THEN 'YES'
> > > > ELSE 'NO' END AS [IsMonday]
> > > > FROM
> > > > #Temp
> > > > - Anith
> Thanks for your help.
> > Cheer up! It happens to me all the time
> > "HAVE COFFEE, BE HAPPY" :-)
> > - Anith
> > > I guess I got lazy when I answered.
> > > And sorry, I missed the Monday part of the question.
> > > I need a coffee.
> > > > How about...
> > > > SET DATEFIRST 1
> > > > BEGIN
> > > > SELECT
> > > > WHEN 1 THEN 'YES'
> > > > ELSE 'NO' END AS [IsMonday]
> > > > END
> > > > Or if you need to use them in JOINs , create a #temp
> > > > table
> > > > SET DATEFIRST 1
> > > > CREATE TABLE #Temp(testDate DATETIME)
> > > > BEGIN
> > > > END
> > > > SELECT
> > > > testDate,
> > > > CASE DATEPART(dw, testDate)
> > > > WHEN 1 THEN 'YES'
> > > > ELSE 'NO' END AS [IsMonday]
> > > > FROM
> > > > #Temp
> > > > - Anith
Also, your request is for a means of returning an infinite number of
results, since there willl be infinite Mondays after, say, next
Monday. Doesn't seem very practical. :)
>sp_listalldaysfrom('1/1/2002')
> 1/1/2002
> 1/2/2002
> 1/3/2002
> ...
>> Something like this?
>> SET DATEFIRST 1
>> SELECT
>> dateCol,
>> CASE DATEPART(dw, dateCol)
>> WHEN 1 THEN 'YES
>> ELSE 'NO'
>> END AS [IsMonday]
>> FROM
>> yourTable
>> - Anith
>> > I need a query to list all dates from a certain date. I am not sure if
>> this
>> > is possible. I want this for a report that will show every monday from
>a
>> > certain date and then I will have a sub-report for the detail if there
>is
>> > any. The dates will show me the ones I do not have detail for.
1. date in query (date to int)
Does anyone knows why?
my query : select mydate from mytable where mydate = 37569
returns mydate = 5/17/2003
it should returns
5/15/2003
2. Converting 4GL to Unix-C/SQL
3. SQL Query - date range in a date range
4. VISUAL CAFE JAVA 2.0--Great $!
5. Query datetime-field by date when field contains date + time
6. Interdev and date parameters
7. find previous date in a range of dates query question
8. *****IGNORED WORDS IN QUERY ERROR*****
9. Single query to find date between 2 dates
10. SQL query : between two dates when dates are varchar datatype
11. Query for Date when there's no date field
12. Selecting dates in a query on a part of a date-syntax
13. date/time field query from access97 query