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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Run tsql in a sequence

Author  Topic 

bconner
Starting Member

48 Posts

Posted - 2012-02-21 : 09:34:30
I am trying to run a stored procedure in a sequence
Basically I want it to run the following order

1. CPC
2. 65 Years and Older
3. $250.01 To $999.99
4. GREATER THAN $1000
5. LESS THAN $250







BEGIN
UPDATE dbo.Tbl_AP
SET [Work Area] = 'CPC'
FROM dbo.Tbl_AP T1
WHERE MRN_CPC_ONLY = 'YES' AND [Work Area] IS NULL
END


BEGIN
UPDATE dbo.Tbl_AP
SET [Work Area] = '65 YEARS AND OLDER'
FROM dbo.Tbl_AP T1
JOIN dbo.vw_65_And_Older T2 ON T1.[MEDICAL RECORD] = T2.[MEDICAL RECORD]
END


BEGIN
UPDATE dbo.Tbl_AP
SET [Work Area] = '$250.01 To $999.99'
FROM dbo.Tbl_AP T1
JOIN dbo.[vw_250_To_999] T2 ON T1.[MEDICAL RECORD] = T2.[MEDICAL RECORD]
WHERE [Work Area] IS NULL
END


BEGIN
UPDATE dbo.Tbl_AP
SET [Work Area] = 'GREATER THAN $1000'
FROM dbo.Tbl_AP T1
JOIN dbo.vw_Greater_Than_1000 T2 ON T1.[MEDICAL RECORD] = T2.[MEDICAL RECORD]
WHERE [Work Area] IS NULL
END


BEGIN
UPDATE dbo.Tbl_AP
SET [Work Area] = 'LESS THAN $250'
FROM dbo.Tbl_AP T1
JOIN dbo.vw_Less_Than_250 T2 ON T1.[MEDICAL RECORD] = T2.[MEDICAL RECORD]
WHERE [Work Area] IS NULL
END















Brian

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-21 : 09:52:26
sorry what is the issue here ? your query is not working ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bconner
Starting Member

48 Posts

Posted - 2012-02-21 : 10:06:16
I need for the above mentioned queries to run in order 1,2,3...etc.
For example there will be some invoices that are CPC with an invoice balance less than $250. If it is CPC I want that to take precedence over it being less than $250 and stamp the invoice CPC.

Brian
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-21 : 11:00:24
The code you have there will run in the sequence they are listed. If that matches the sequence that you want, and you've got where clauses to ensure that a column can't get updated multiple times (which you have in all but the second), then that should work as you want.

Does that not happen?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

bconner
Starting Member

48 Posts

Posted - 2012-02-21 : 12:18:15
Ok, I feel like a fool! I was looking at the stored procedure on the development machine not the production machine... Sorry... It is working correctly..... I need more sleep and less coffee!

Brian
Go to Top of Page
   

- Advertisement -