﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / How To Validate in Procedure / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 01:44:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>Might incorporating this work?[code="sql"]select case when isnumeric(left(DCPI_Date,4))=1then DCPI_Dateelse '19000101'END [/code]when doing your insert into dbo.Reliance_Master 			Then later in your SSIS redirect those rows that have 1900-01-01 as the date to an separate file for visual inspection or other form of importing, for instance.</description><pubDate>Thu, 11 Apr 2013 11:33:19 GMT</pubDate><dc:creator>mmartin1</dc:creator></item><item><title>RE: How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>Please try this,create procedure [dbo].[USP_Reliance_Master_Upload]  as  begin  	 	--declare @dt datetime , @Mnth varchar(10)------ If the data consist of Mnth column data as null or blank valuesIF EXISTS (SELECT 1 FROM Ram_Reliance_Master where ISNULL(RTRIM(LTRIM(Mnth)), '') = '')RETURN -1		BEGIN TRY    	IF EXISTS (SELECT   1  from  Ram_Reliance_Master 	WHERE  DCPI_Date =  convert(varchar(10),convert(datetime,DCPI_Date),101)  )		RETURN -1		-- The Date Field is In Correct Formate so Please Check Your Data			END TRY    	BEGIN CATCH  	RETURN -1		-- The Date Field is In Correct Formate so Please Check Your Data	END CATCH 				insert into dbo.Reliance_Master 			(Mnth,DCPI_Date,GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,insertDt,Year)	select  			 Mnth,convert(datetime,DCPI_Date),GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,cast(getdate() as DATE),DATEPART(YY,DCPI_Date)   	 from Ram_Reliance_Master		 			      end  </description><pubDate>Sat, 26 Jan 2013 23:28:11 GMT</pubDate><dc:creator>uravindarreddy</dc:creator></item><item><title>RE: How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>What datatype are you using for DCPI_Date in Reliance_Master and Ram_Reliance_Master?</description><pubDate>Fri, 25 Jan 2013 01:48:48 GMT</pubDate><dc:creator>Sean Pearce</dc:creator></item><item><title>RE: How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>[quote][b]sarwaanmca (1/23/2013)[/b][hr]I Created a one Procedure ..its given Below...[code="sql"]create procedure [dbo].[USP_Reliance_Master_Upload]  as  begin  	 	declare @dt datetime , @Mnth varchar(10)		BEGIN TRY    	SELECT   @dt = convert(varchar(10),convert(datetime,DCPI_Date),101)  from  Ram_Reliance_Master 	END TRY    	BEGIN CATCH  	RETURN-1		-- The Date Field is In Correct Formate so Please Check Your Data	END CATCH 			BEGIN TRY 	SELECT   @Mnth = Mnth from  Ram_Reliance_Master where isnull(Mnth,'')!=''	END TRY    	BEGIN CATCH  	RETURN-1  	END CATCH          -- The Date Field Should Not Be Null	 		insert into dbo.Reliance_Master 			(Mnth,DCPI_Date,GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,insertDt,Year)	select  			 Mnth,convert(datetime,DCPI_Date),GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,cast(getdate() as DATE),DATEPART(YY,DCPI_Date)   	 from Ram_Reliance_Master		 			      end  [/code]&amp;lt;snipped&amp;gt;1)Mnth Column Should be Not Null  2)The DCPI_Date Field Should be 101 Format ie, (MMDDYYYY)Otherwise that Procedure will not Execute ... it should be terminate ...should not commit any Rows...How To Validate in Procedure ?I dont know well the Above Query is working fine or not..or any other idea Please Share and Support Me...Thanks &amp; RegardsSaravanan.D[/quote]TRY-CATCH will not work for your purpose because control is passed to the CATCH block only when the TRY block code generates an error of sufficient severity. In both of your TRY-CATCH constructs, the CATCH blocks will execute only when the  TRY code generates errors. The first TRY-CATCH will execute the CATCH block if for some reason the DCPI_Date value cannot be converted to a valid datetime, but that doesn't ensure that DCPI_Date is in the 101 MMDDYYYY format you want. For example, 10 June 2012 and 6 October 2012 can both be written as '06-10-2012' or '10-06-2012' depending on which convention your users are following. How SQL Server interprets those strings as dates depends on the DATEFORMAT setting.If you want to verify that the values of variables or parameters are within specified domains before proceeding, you can use IF statements:IF @Mnth IS NULLBEGINRETURNEND&amp;lt;some code to run otherwise&amp;gt;</description><pubDate>Thu, 24 Jan 2013 14:01:47 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>[quote][b]sarwaanmca (1/23/2013)[/b][hr]1)Mnth Column Should be Not Null  [/quote] Add in procedure [code="sql"]IF isnull(@Mnth , '') = ''   RETURN[/code][quote][b]sarwaanmca (1/23/2013)[/b][hr] The DCPI_Date Field Should be 101 Format ie, (MMDDYYYY) [/quote] Use CONVERT function to set its format to 101</description><pubDate>Wed, 23 Jan 2013 03:41:18 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item><item><title>How To Validate in Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic1410366-392-1.aspx</link><description>I Created a one Procedure ..its given Below...[code="sql"]create procedure [dbo].[USP_Reliance_Master_Upload]  as  begin  	 	declare @dt datetime , @Mnth varchar(10)		BEGIN TRY    	SELECT   @dt = convert(varchar(10),convert(datetime,DCPI_Date),101)  from  Ram_Reliance_Master 	END TRY    	BEGIN CATCH  	RETURN-1		-- The Date Field is In Correct Formate so Please Check Your Data	END CATCH 			BEGIN TRY 	SELECT   @Mnth = Mnth from  Ram_Reliance_Master where isnull(Mnth,'')!=''	END TRY    	BEGIN CATCH  	RETURN-1  	END CATCH          -- The Date Field Should Not Be Null	 		insert into dbo.Reliance_Master 			(Mnth,DCPI_Date,GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,insertDt,Year)	select  			 Mnth,convert(datetime,DCPI_Date),GRP_OUTS_RIL,Interest_Cost,OverDue_Earned,Qty,EPI,cast(getdate() as DATE),DATEPART(YY,DCPI_Date)   	 from Ram_Reliance_Master		 			      end  [/code]The Existing Ram_Reliance_Master Table Data is Given Below,[code="sql"]Mnth       DCPI_Date  GRP_OUTS_RIL           Interest_Cost          OverDue_Earned         Qty                    EPI                    Year         ---------- ---------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- -----------  DEC        2012-12-12 NULL                   NULL                   NULL                   5                      2925                   2012         DEC        2012-12-21 NULL                   NULL                   NULL                   0.002                  0.91                   2012         DEC        2012-12-26 NULL                   NULL                   NULL                   0.5                    NULL                   2012         Null       13-02-2012  NULL                   NULL                   NULL                   5                      NULL                   2012         DEC        2012-12-12 NULL                   NULL                   NULL                   5                      2925                   2012         [/code][b]Requirement is...[u][/u][/b]I Build that Stored Procedure in SSIS Package with Job scheduler...In that Procedure i want to check the Ram_Reliance_Master table Value1)Mnth Column Should be Not Null  2)The DCPI_Date Field Should be 101 Format ie, (MMDDYYYY)Otherwise that Procedure will not Execute ... it should be terminate ...should not commit any Rows...How To Validate in Procedure ?I dont know well the Above Query is working fine or not..or any other idea Please Share and Support Me...Thanks &amp; RegardsSaravanan.D</description><pubDate>Wed, 23 Jan 2013 00:06:36 GMT</pubDate><dc:creator>sarwaanmca</dc:creator></item></channel></rss>