SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 End Stored Procedure if no data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kyle Doouss
Yak Posting Veteran

United Kingdom
53 Posts

Posted - 10/15/2013 :  06:09:41  Show Profile  Reply with Quote
Hello I have written the following stored procedure to export a csv file. I am wanting to put a If statement in here so if view UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_VIEW returns nothing then the procedure does not run. I would be glad of any help.

INSERT INTO UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_TABLE_TEMP
SELECT * FROM UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_VIEW


INSERT INTO UDEF_DISPATCHER_INTERFACE_ORDER_LINE_TABLE_TEMP
SELECT * FROM UDEF_DISPATCHER_INTERFACE_ORDER_LINE_VIEW

DECLARE @BcpHeader AS VARCHAR (2000)
DECLARE @BcpLine AS VARCHAR (2000)
DECLARE @FileNameHeader AS VARCHAR (2000)
DECLARE @FileNameLine AS VARCHAR (2000)
DECLARE @FileDateExtension AS VARCHAR (100)
SET @FileDateExtension = + CAST(DATEPART(yyyy,GETDATE()) AS VARCHAR (4))+ RIGHT('0'+ CAST(DATEPART(MM,GETDATE()) AS VARCHAR(2)),2) + RIGHT('0' + CAST(DATEPART(DD,GETDATE()) AS VARCHAR(2)),2) + RIGHT('0' + CAST(DATEPART(HOUR,GETDATE()) AS VARCHAR(2)),2) + RIGHT('0' + CAST(DATEPART(MI,GETDATE()) AS VARCHAR(2)),2) + RIGHT('0'+ CAST(DATEPART(SS,GETDATE()) AS VARCHAR(2)),2)
SET @FileNameHeader = 'UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_' + @FileDateExtension+ '.csv'
SET @FileNameLine = 'UDEF_DISPATCHER_INTERFACE_ORDER_LINE_' + @FileDateExtension+ '.csv'
SET @BcpHeader = 'bcp "Select * FROM HBSLIVE.dbo.UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_TABLE_TEMP " QUERYOUT \\appserver\Dispatcher\testing\' +@FileNameHeader+ ' -c -t, -T -S'
SET @BcpLine = 'bcp "Select * FROM HBSLIVE.dbo.UDEF_DISPATCHER_INTERFACE_ORDER_LINE_TABLE_TEMP " QUERYOUT \\appserver\Dispatcher\testing\' +@FileNameLine+ ' -c -t, -T -S'

EXEC xp_cmdshell @BcpHeader

EXEC xp_cmdshell @BcpLine

INSERT INTO UDEF_DISPATCHER_DEL_NOTE_REPOSITORY
SELECT REPLACE(REPLACE(Order_Id,'"',''),'-VOW',''),CONVERT(DATETIME,GETDATE (),103) FROM UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_TABLE_TEMP

TRUNCATE TABLE UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_TABLE_TEMP
TRUNCATE TABLE UDEF_DISPATCHER_INTERFACE_ORDER_LINE_TABLE_TEMP

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 10/15/2013 :  07:14:12  Show Profile  Visit webfred's Homepage  Reply with Quote
Maybe this as first statement in your proc?

if not exists(SELECT * FROM UDEF_DISPATCHER_INTERFACE_ORDER_HEADER_VIEW)
begin
return 0
end


Too old to Rock'n'Roll too young to die.
Go to Top of Page

Kyle Doouss
Yak Posting Veteran

United Kingdom
53 Posts

Posted - 10/15/2013 :  08:19:28  Show Profile  Reply with Quote
Great thanks it worked
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000