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
 Help with stored procedure

Author  Topic 

awalker
Starting Member

12 Posts

Posted - 2012-12-01 : 00:24:21
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 - 2012-12-01 : 00:49:04
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

39 Posts

Posted - 2012-12-01 : 08:20:00
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-03 : 02:03:28
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
   

- Advertisement -