Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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'

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

Flowing Fount of Yak Knowledge

2242 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);

Go to Top of Page
  Previous Topic Topic Next 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.03 seconds. Powered By: Snitz Forums 2000