Jim Beam
Posting Yak Master
137 Posts |
Posted - 2010-10-03 : 10:24:35
|
Hi all,I've got sections of code I'd like to transfrom into a single stored procedure. At the moment, we run each of the five sections separately, the first is a join (into which we paste a bunch of phone numbers )that yields phone no's and a text string, the next two are inserts of that join's result-set into two tables (OutQueue and Block), the fourth is a result check that updates comments column of the Block table and does a rowcount, and the last is an update that updates a 'Comment' column, then runs a check that is possibly not needed.What I'd like to know is:1) what variables will be needed (ie for the Rowcount, and how I can send that off for reporting);2) how to avoid repeating the blocks of phone numbers;3) whether the last check is necessary;4) the best overall way to write the Sproc. Here's the code so far, I'd be grateful for all your help, people!Cheers,Jim.----------------------------- Initial paste of phone no's + join of message text--, ---------------------------SELECT *FROM (SELECT '27724748733' AS PHONE UNIONSELECT '27824474244' AS PHONE UNION) aINNER JOIN Outqueue2 b ON b.phone = a.phone AND b.msg = 'Your membership has been cancelled, DO NOT REPLY.'ORDER BY a.phone----------------------------- Insert Confirmation MT---------------------------GOINSERT INTO DBSRVR2.Queues.dbo.Outqueue ( phone, routing, service, keyword, keyid, msg, result, origin )SELECT a.phone, c.freeOffAggMt AS routing, ISNULL(d.service, 0) AS service, ISNULL(d.keyword, 0) AS keyword, ISNULL(d.keyid, 0) AS keyid, 'Your membership has been cancelled, DO NOT REPLY.' AS msg, 61 AS result, 3 AS originFROM (SELECT '27724748733' AS PHONE UNIONSELECT '27824474244' AS PHONE UNION) aINNER JOIN DBSRVR1.OUTNOW.DBO.Phonelist b (read committed snapshot) ON b.phone = a.phoneINNER JOIN DBSRVR1.OUTNOW.DBO.DefineMtRoutes c (read committed snapshot) ON c.aggregator = b.aggregator AND c.network = b.networkLEFT JOIN DBSRVR1.OUTNOW.DBO.Services d (read committed snapshot) ON d.userid = b.userid AND d.service = b.srvspref----------------------------- Insert into BLOCK---------------------------GOINSERT INTO DBSRVR2.QUEUES.DBO.Block ( phone, aggregator, comment )SELECT x.phone, 0 AS aggregator, 'WASP complaint (BKM)' AS comment-- Rowcount (for future reporting)SELECT COUNT(*) AS totalFROM (SELECT '27724748733' AS PHONE UNIONSELECT '27824474244' AS PHONE UNION) xLEFT JOIN Block y (NOLOCK) ON y.phone = x.phone AND y.aggregator = 0WHERE (y.phone IS NULL)----------------------------- Check results---------------------------GOUPDATE y SET comment = 'WASP complaint (BKM)'-- SELECT y.*FROM (SELECT '27724748733' AS PHONE UNIONSELECT '27824474244' AS PHONE UNION) xINNER JOIN Block y (read committed snapshot) ON y.phone = x.phone AND y.aggregator = 0WHERE (comment LIKE '%comment provided') |
|