Click here to Skip to main content
12,547,922 members (47,986 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
i have used triger on table.This triger is fire when i insert data in LeaveFrom Table.In My Stored procedure if condition i have put.when i put if condition code in if condition is not working.If i remove if codition then insert work successfully.My I have try this code in Query is comming when if is fire.but what is problem in storeprocedure code,that i dont know.

My Triger is:
ON dbo.LeaveForm
EXEC Biometrics_InsertFrom_LeaveForm

My Storeprocedure is..
ALTER PROCEDURE dbo.Biometrics_InsertFrom_LeaveForm

Declare @Count int
Declare @LeaveFrom datetime
Declare @LeaveTo datetime
Declare @Approve bit
set @Approve='True'
		select @Count=count(*) from LeaveForm where Approve=@Approve and (convert(varchar,@LeaveFrom,101)=convert(varchar,getdate(),101) or convert(varchar,@LeaveTo,101)=convert(varchar,getdate(),101))
		if(@Count > 0)
			INSERT INTO Biometrics (PCL,PLE)
			VALUES        (getdate(),getdate())
Posted 4-Feb-13 20:59pm
Updated 4-Feb-13 21:00pm
__TR__ 5-Feb-13 3:06am
Looks like @Count is not greater than 0, hence the insert statement is not getting executed. Also you are not passing any dates to @LeaveFrom and @LeaveTo. If you use them in your query without passing any value it will be null and your query may not return any rows.
Print @Count to check the value of @Count.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It works for me, so my assumption is that your WHERE condition is returning no records.
I'm not quite sure what you are trying to do, but the condition does look a bit rubbish. If you are trying to see in the current date is between two leave dates, then why not just use BETWEEN? Never convert dates to a string to compare them!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100