how to check the date by using procedure.

Posted by reddysankark-13471 under Sql Server on 2/5/2012 | Points: 10 | Views : 916 | Status : [Member] | Replies : 3
i want to develop one software.for that i will book one date how to check if that date is already there r not in database by using procedure

sankarreddy


Responses

Posted by: Sksamantaray on: 2/5/2012 [Member] Silver | Points: 25

Up
0
Down
create procedure spchkDate
@inputDate datetime
as
begin
declare @ctr int
select @ctr= count(*) from [tableName] where [dateColumnName]=@inputDate
end

then in your code :
int variable=call procedure
if(variable==0)
//date is not available
else
//date is available


Thanks,
Sanjay

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down

Hi sankarreddy,

Create Procedure sp_checkDate
@joinDate datetime
as
Begin
select * from Tablename where join_date=@joinDate
end

Hope this will help

Regards

sriram

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
Hello,

Use the following query in your stored procedure

if not exists(select * from tablename where [datecolumnname]=@GivenDate)
return 1
else
return 2


then in cs file with this return value proceed the code as follows.If the date doesnot exists do certain task else other task,

  cmd = new SqlCommand("SC_SP_CheckDate", con);

cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramReturn = cmd.Parameters.Add("ReturnValue", SqlDbType.Int);
paramReturn.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.AddWithValue("@GivenDate",Date);
cmd.ExecuteNonQuery();
con.Close();
if ((int)cmd.Parameters["ReturnValue"].Value == 1)
{
}
else
{
}


reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response