Stored Procedures SQL Server
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
Just use an insert:
CREATE PROCEDURE spGetMemReminder
AS
INSERT INTO YourTableNameHere (FullName, ExpiryDate)
SELECT users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATEif expiryDate is a date column it is better to do date compare than to convert both sides.
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
Use an insert statement, that is not why I am posting a reply. There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert. Never underestimate the power of human stupidity RAH
-
Just use an insert:
CREATE PROCEDURE spGetMemReminder
AS
INSERT INTO YourTableNameHere (FullName, ExpiryDate)
SELECT users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATEif expiryDate is a date column it is better to do date compare than to convert both sides.
-
Use an insert statement, that is not why I am posting a reply. There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert. Never underestimate the power of human stupidity RAH
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
Hai.... You can do it by table varible. create proc
spGetMemReminder
as
select users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
endGO
CREATE PROCEDURE InsertMember
AS
BEGIN
SET NOCOUNT ON
DECLARE @TABLE TABLE(fullname nvarchar(10), expiryDate datetime)insert into @TABLE exec spGetMemReminder insert into yourothertable select \* from @TABLE SET NOCOUNT OFF
END
-
I have created a stored procedure which lists all customers that have 7 days left on their membership. ---------- create proc spGetMemReminder as select users.fullname, membership.expiryDate from membership inner join users on membership.uid=users.uid where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105) ------- I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
I think 'Insert into' query will help you