Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


append sp


append sp

Author
Message
sdhanpaul
sdhanpaul
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 566
Hi,

not quite sure if this is info info...but i wanna convert this sp to an append sp.


with rows as (
select *, row_number() over (order by emppin, trxdate) as rownum
from rawtrx)
select *, rowsMinusOne.trxtime as trxtimeIN,
ISNULL(rows.trxtime,1) as trxtimeOUT
from rows as rowsMinusOne
left outer join rows
on rows.rownum = rowsMinusOne.rownum + 1 and rows.emppin = rowsMinusOne.emppin



Think you can help?
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8562 Visits: 18143
I'm not sure what you mean. That's not an sp and I'm unaware of the term append sp.
Could you clarify what you need?


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
sdhanpaul
sdhanpaul
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 566

ALTER PROCEDURE dbo.zz_sp_testing_inout
AS
WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum
FROM rawtrx)
SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT
FROM rows AS rowsMinusOne LEFT OUTER JOIN
rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin = rowsMinusOne.emppin



Okay, does that look more like a stored procedure?

well this works exactly the way I want it to work, it returns the records...I want to add the records returned by this code above to a table.

is that possible?
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 6078
Yes, if the table already exists then add an INSERT INTO command below the CTE declaration above the SELECT.

If the table doesnt exist, add the INTO clause above the FROM.

WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum
FROM rawtrx)
INSERT INTO atable (col1, col2,.................)
SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT
FROM rows AS rowsMinusOne LEFT OUTER JOIN
rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin



WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum
FROM rawtrx)
SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT
INTO atable
FROM rows AS rowsMinusOne LEFT OUTER JOIN
rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 6078
Yes, if the table already exists then add an INSERT INTO command below the CTE declaration above the SELECT.

If the table doesnt exist, add the INTO clause above the FROM.

WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum
FROM rawtrx)
INSERT INTO atable (col1, col2,.................)
SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT
FROM rows AS rowsMinusOne LEFT OUTER JOIN
rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin



WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum
FROM rawtrx)
SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT
INTO atable
FROM rows AS rowsMinusOne LEFT OUTER JOIN
rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


sdhanpaul
sdhanpaul
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 566
ah! yes, i did try this ...i got an error but i know what the reason for the error is so it will work. Thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search