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
 Assign variable according to records returned

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-05-30 : 07:26:56
The database WORKCALENDAR has records only for working days.
I want to declare a variable that is '1' in case that the query that checks if today is a workingday returns a match or '0' in case it doesn't.
declare @workday binary
set @workday = ..??... from dbo.WORKCALENDAR where DATEDIFF(day, TRANSDATE, GETDATE()) =0

I've been trying with ISNULL in the last hour but I just don't get it.
What function does this trick?

Martin

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-05-30 : 07:32:22
declare @workday int = 0
select @workday = 1 from dbo.WORKCALENDAR where DATEDIFF(day, TRANSDATE, GETDATE()) =0


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-05-30 : 07:43:48
yeah... close but not close enough!
Thank you Nigel
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-05-30 : 09:00:40
declare @workday int
set @workday = 0

if exists(select * from dbo.Workcalendar where DATEDIFF(day, TRANSDATE, GETDATE()) =0)
begin
set @workday = 1
end



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

- Advertisement -