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.
Author |
Topic |
mayerl
Yak Posting Veteran
95 Posts |
Posted - 2011-05-10 : 09:43:54
|
Good morning,I have been asked not to send an empty file to our shipment database, a reasonable request. I was thinking I could make a step in the job that says look at today's data is there any?:select case when COUNT(*) > 0 then '1' else 0end records_sentfrom tbl_FAR_PreLoadwhere Ship_Dt >= getdate()-1AND Ship_Dt <= getdate() Is there a way to say in the job step if its 0 then exit? I cant seem to find that little piece of code. Any thoughts would be great.Thanks in advanceLaura |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-05-11 : 04:24:48
|
As an approach:Create a first jobstep which executes the following T-SQL statement:IF (select COUNT(*) from tbl_FAR_PreLoad where Ship_Dt >= getdate()-1 AND Ship_Dt <= getdate())=0BEGINRAISERROR ('Fail!', 16, 1)ENDAnd if the step fails then quit the job or whatever you want to do then... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
mayerl
Yak Posting Veteran
95 Posts |
Posted - 2011-05-11 : 14:19:28
|
Perfect! Thanks so much.Laura |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-05-12 : 03:25:30
|
orIF not exists(select * from tbl_FAR_PreLoad where Ship_Dt >= getdate()-1 AND Ship_Dt <= getdate())BEGINRAISERROR ('Fail!', 16, 1)ENDMadhivananFailing to plan is Planning to fail |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-05-12 : 03:45:11
|
OK, Laura, you should prefer madhi's solution because it will be much faster whenever there is existent data to use in the next job step. I believe that, in most cases, there will be data... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|