[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1384
  • Last Modified:

If select datename(dw,getdate(@SelectedDate)) is Sunday

@SelectedDate is an actual date like 04/26/2006

I don't know if I'm doing this line right
select datename(dw,getdate(@SelectedDate))
but

I want to say if select datename(dw,getdate(@SelectedDate))  is Sunday then
    First = 1

if Monday then
    First = 2

etc.

How do I do that?

****************************

IF @FreqID = 4
BEGIN
UPDATE SusansTable
     SET
         FreqID = @FreqID,
         StartDate = 01/01/1900,
         First = 2
         
WHERE SomeID = @SomeID
END
0
net_susan
Asked:
net_susan
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hi net_susan,
IF @FreqID = 4
BEGIN
UPDATE SusansTable
     SET
         FreqID = @FreqID,
         StartDate = 01/01/1900,
         [First] = CASE datename(dw,getdate()) WHEN 'Sunday' then 1
            WHEN 'Monday' then 2
            WHEN 'Tuesday' then 3
            WHEN 'Wednesday' then 4
            WHEN 'Thursday' then 5
            WHEN 'Friday' then 6
            ELSE 7 End
                     
WHERE SomeID = @SomeID
END



select datename(dw,getdate())

Aneesh R!
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
You can rplace GETDATE() with @selecteddate


IF @FreqID = 4
BEGIN
UPDATE SusansTable
     SET
         FreqID = @FreqID,
         StartDate = 01/01/1900,
         [First] = CASE datename(dw,@selectedDate) WHEN 'Sunday' then 1
            WHEN 'Monday' then 2
            WHEN 'Tuesday' then 3
            WHEN 'Wednesday' then 4
            WHEN 'Thursday' then 5
            WHEN 'Friday' then 6
            ELSE 7 End
                     
WHERE SomeID = @SomeID
END



0
 
MacNuttinCommented:
Here's some ideas:

DECLARE @DAY varchar(10), @SelectedDate datetime
SET @SelectedDate = getdate()
print @SelectedDate
SET @DAY = (select datename(dw,@SelectedDate))
print @Day
SET @DAY = (select datename(dd,@SelectedDate))
print @Day
0
 
net_susanAuthor Commented:
Thank you!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now