SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How To Validate in Procedure


How To Validate in Procedure

Author
Message
sarwaanmca
sarwaanmca
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 193
I Created a one Procedure ..its given Below...

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



The Existing Ram_Reliance_Master Table Data is Given Below,

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



Requirement is...

I Build that Stored Procedure in SSIS Package with Job scheduler...
In that Procedure i want to check the Ram_Reliance_Master table Value

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 & Regards
Saravanan.D
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5430 Visits: 4076
sarwaanmca (1/23/2013)
1)Mnth Column Should be Not Null
Add in procedure

IF isnull(@Mnth , '') = '' 
RETURN



sarwaanmca (1/23/2013)
The DCPI_Date Field Should be 101 Format ie, (MMDDYYYY)

Use CONVERT function to set its format to 101

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
wolfkillj
wolfkillj
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1486 Visits: 2582
sarwaanmca (1/23/2013)
I Created a one Procedure ..its given Below...

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



<snipped>

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 & Regards
Saravanan.D


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 NULL
BEGIN
RETURN
END
<some code to run otherwise>

Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Sean Pearce
Sean Pearce
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1808 Visits: 3432
What datatype are you using for DCPI_Date in Reliance_Master and Ram_Reliance_Master?



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
uravindarreddy
uravindarreddy
Mr or Mrs. 500
Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)Mr or Mrs. 500 (579 reputation)

Group: General Forum Members
Points: 579 Visits: 579
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 values
IF 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
MMartin1
MMartin1
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2827 Visits: 2031
Might incorporating this work?


select case when isnumeric(left(DCPI_Date,4))=1
then DCPI_Date
else '19000101'
END


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.

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search