SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with stored procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

awalker
Starting Member

12 Posts

Posted - 12/01/2012 :  00:24:21  Show Profile  Reply with Quote
I am trying to make a stored procedure where it gets passed a datetime, I take the datetime that was passed and call DATENAME to get the name of the day and set it to a variable. I am not sure this made sence but here is what I have so far, it just does not seem to be working.


@appointmentDate datetime

declare dow varchar(15);
set dow = datename(dw, @appointmentDate);

update dbo.Appointments where @dow = 'Tuesday'

awalker
Starting Member

12 Posts

Posted - 12/01/2012 :  00:49:04  Show Profile  Reply with Quote
I think I figured it out. I needed to have it be

select dow = datename(dw, @appointmentDate);
Go to Top of Page

Elizabeth B. Darcy
Starting Member

United Kingdom
39 Posts

Posted - 12/01/2012 :  08:20:00  Show Profile  Reply with Quote
If dow is a scalar variable, you would do this:
declare @dow varchar(15)
If that is so, then you can use set or select - either should work, notwithstanding some subtle differences.

On the other hand, if dow is a column in a table, then you should not have the declare statement that is in your posting.

______________________________________________
-- "If a book is well written, I always find it too short"
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 12/03/2012 :  02:03:28  Show Profile  Reply with Quote
Case 1:

@appointmentDate datetime

declare @dow varchar(15);
set @dow = datename(dw, @appointmentDate);

update dbo.Appointments
SET columnName = value
where @dow = 'Tuesday'

Case 2:
@appointmentDate datetime

declare @dow varchar(15);
select @dow = datename(dw, @appointmentDate);



--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000