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 2005 Forums
 Transact-SQL (2005)
 how to run the following queries one after other?

Author  Topic 

raaj
Posting Yak Master

129 Posts

Posted - 2011-01-30 : 17:02:24
Hi Guys,
I am having a table named 'Employee' and it has many columns.
This table gets data from different other tables.
I have 3 insert select statements which populates this table and when i schedule this query as a job, I want to run those queries in sequential order.
-- step 1:
Insert into Employee (col1,col2,col3)
Select col1,col2,col3 from DetailTable
-- step 2:
Insert into Employee (col4,col5,col6)
Select col4,col5,col6 from HistoryTable
-- step 3:
Insert into Employee (col7,col8)
Select col7,col8 from PersonnelTable

Now I want to create a job with the above queries which runs every 3 hrs.
Now what I want is :
When I create a job with above T SQL statements, Do they run in the same order as I have written the queries?
Like first I want to run the step 1 query and then step 2 query and then step 3 query?
Do I need to add any extra clause to make them run one after another?

any ideas???
Raaj.

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-30 : 17:11:40
The go in the order you specify, and/or the order written. If you actually tried setting up an agent job, this would be fairly easy to identify. You can do it 3 separate job steps, or in 1 T-SQL step inthe order you indicate. The run in the order from top to bottom. You could also do it in one step

INSERT INTO employee (col1,col2,col3,col4,col5,col6,col7,col8)
SELECT col1,col2,col3, NULL, NULL,NULL, NULL,NULL
UNION ALL
SELECT NULL, NULL,NULL,col4,col5,col6, NULL,NULL
UNION ALL
SELECT NULL, NULL,NULL, NULL,NULL,NULL,col7,col8


One is left to wonder what possible benefit those queries have in the final result. Every time it runs, Columns 1-6 will be empty for every record in the personnel table. Also..populating the employee table from personnel table every 3 hours might be a bit redundant unless you have really high turnover. ;) . I am sure your query was more for demonstration...but still...

perhaps you lay out what you are actually trying to do, and we can like give better suggestions.



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page
   

- Advertisement -