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
 question

Author  Topic 

Trininole
Yak Posting Veteran

83 Posts

Posted - 2010-05-12 : 15:22:20
How would i write the syntax if today's date was on a thursday and today's date is not located in the table called "holiday", how would i make it write "yes" if today's date is not in the table and "no" if it is in the table?

Roger DeFour

gavakie
Posting Yak Master

221 Posts

Posted - 2010-05-12 : 15:28:08
Would it only be todays date or any date?
Go to Top of Page

Trininole
Yak Posting Veteran

83 Posts

Posted - 2010-05-12 : 15:28:31
It would be today's date

Roger DeFour
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-12 : 15:33:36
[code]
-- making testdata
set nocount on
declare @holiday table (name_of_day varchar(30))
insert @holiday
select 'Monday' union all
select 'Tuesday' union all
select 'Wednesday' union all
select 'Friday'



if exists(select * from @holiday where name_of_day = datename(dw, getdate())
and datename(dw, getdate()) = 'Thursday')
begin
print 'no'
end
else
begin
print 'yes'
end
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2010-05-12 : 15:43:53
Select datecolumn, case when date = getdate() then 'No' else 'Yes' End as columnname
from holiday
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-12 : 15:56:56
quote:
Originally posted by gavakie

Select datecolumn, case when date = getdate() then 'No' else 'Yes' End as columnname
from holiday


This will not work because of the time part in getdate()


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-12 : 15:57:36
I have misunderstood.
Here is my correction:
-- making testdata
set nocount on
declare @holiday table (holidate datetime)
insert @holiday
select '20100513' union all
select '20100512' union all
select '20100530' union all
select '20100529'



if exists(select * from @holiday where holidate = dateadd(dd,datediff(dd,0,getdate()),0)
and datename(dw, getdate()) = 'Thursday')
begin
print 'no'
end
else
begin
print 'yes'
end

You can test it also if you replace Thursday by Wednesday.

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -