September 6, 2010 at 3:21 am
i want to insert data into table using store procedure.i have mention certain condition using dropdownlist in my program.i.e. according to selected value of dropdown list only that parameters value should be inserted,rest of the parameters are not supplied in some cases.so i am getting problem regarding parameters that i am passing through SP and whose values are not supplied in program.how can i do it?my SP is:
ALTER PROCEDURE [dbo].[SubmitReport]
@empname varchar(20),
@email varchar(30),
@designation varchar(20),
@reportto varchar(20),
@fromdate nvarchar(20),
@todate nvarchar(20),
@attachedfile nvarchar(200),
@days int,
@date1 nvarchar(20),
@description1 varchar(50),
@date2 nvarchar(20),
@description2 varchar(50),
@date3 nvarchar(20),
@description3 varchar(50),
@date4 nvarchar(20),
@description4 varchar(50),
@date5 nvarchar(20),
@description5 varchar(50),
@date6 nvarchar(20),
@description6 varchar(50)
AS
BEGIN
INSERT INTO UserDetails(empname,email,designation,reportto,fromdate,todate,attachedfile,days,date1,description1,date2,description2,date3,description3,date4,description4,date5,description5,date6,description6)
VALUES(@empname,@email,@designation,@reportto,@fromdate,@todate,@attachedfile,@days,@date1,@description1,@date2,@description2,@date3,@description3,@date4,@description4,@date5,@description5,@date6,@description6)
END
In case when i have selected only 2 days i will have only 2 parameters @date1,@description1 and @date2, @description2.what condition can i put in my SP so that it can submit data into table which are supplied.
September 6, 2010 at 3:45 am
As per my understanding of the problem following paramters may be NULL as per user's selection:
@date1 nvarchar(20),
@description1 varchar(50),
@date2 nvarchar(20),
@description2 varchar(50),
@date3 nvarchar(20),
@description3 varchar(50),
@date4 nvarchar(20),
@description4 varchar(50),
@date5 nvarchar(20),
@description5 varchar(50),
@date6 nvarchar(20),
@description6 varchar(50)
so you can put default NULL value for the parameters like:
@date1 nvarchar(20) = NULL ,
@description1 varchar(50) = NULL ,
@date2 nvarchar(20) = NULL,
@description2 varchar(50) = NULL,
(You can add the same for rest of the parameters)
Whenever value for the above parameters are not supplied then it will supply NULL for that parameters.
You need to modify the calling program so that supplied paramters are same so SQL will not throw supplied paramters are less related error.
Thanks
September 6, 2010 at 3:57 am
thanks sir!! some time these silly things doesnt strike in my mind. thanks a lot.:-):-P
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply