Hi All ,
Problem :
I have database table as follows
column datatype
id bigint
PatientID bigint
operationID int
I am writing stored procedure as follows using dynamic query
ALTER PROCEDURE [dbo].[SP_SearchPat]
@id bigint=null,
@PatientID varchar(13)=null,
@operationID varchar(30)=null
AS
BEGIN
declare
@id bigint=null,
@PatientID varchar(13)=null,
@operationID varchar(30)=null
AS
BEGIN
declare
@isPatientID varchar(13),
@isoperationID varchar(30),
@sqlquery varchar(1000),
@sqlfinal varchar(2000)
SET NOCOUNT ON;
set @sqlquery= 'select * from Patients where id='+CAST(@id as varchar)+'
if (@PatientID = 0)
begin
set @isPatientID =' '
end
else
begin
set @isPatientID =' and PatientID ='+CAST(@PatientID as varchar)
end
if (@operationID = 0)
begin
set @isoperationID =' '
end
else
begin
set @isoperationID =' and operationID='+CAST(@operationID as varchar)
end
set @sqlfinal=@sqlquery@isPatientID+@operationID;
print @sqlfinal
exec(@sqlfinal)
end
@isoperationID varchar(30),
@sqlquery varchar(1000),
@sqlfinal varchar(2000)
SET NOCOUNT ON;
set @sqlquery= 'select * from Patients where id='+CAST(@id as varchar)+'
if (@PatientID = 0)
begin
set @isPatientID =' '
end
else
begin
set @isPatientID =' and PatientID ='+CAST(@PatientID as varchar)
end
if (@operationID = 0)
begin
set @isoperationID =' '
end
else
begin
set @isoperationID =' and operationID='+CAST(@operationID as varchar)
end
set @sqlfinal=@sqlquery@isPatientID+@operationID;
print @sqlfinal
exec(@sqlfinal)
end
whenever i try to execute this stored procedure using operationId=132321321313 then above mentioned error is thrown.
Please suggest how to solve the above error
SOLUTION :
Hi,
You are out of the allowed values can be stored in an int type. int type can store data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).
You may start using bigint, it can store data from -2^63 (-9,223,372,036,854,775,808) through 2^63-1 (9,223,372,036,854,775,807).
I hope it helps.
Solution :
Comments
Post a Comment