June 9, 2008 at 4:31 pm
Hi,
I've a column Event_Desc(255)nvarchar in a table. If I insert a record in it through stored procesure which is more than 255 chars, it gives error.
Can any one give me the code in stored proc format which will check if length of event_desc entered by user not more than 255 & that if it is it'll just accept first 255 chars & insert it into database.
I'm using SQL Server 2000.
Here is my existing stored proc:
CREATE PROCEDURE [dbo].[AddSystemEvent]
(
@ScannerID As Int,
@TimeDate DateTime,
@EventID As Int,
@EventDesc NVarchar(256)
)
AS
Begin
Insert Into tb_system_event
(Scanner_ID, Time_Date, Event_ID, Event_Description)
Values (@ScannerID, @TimeDate, @EventID, @EventDesc)
End
Appreciate any help!!!!
Thanks!!!
June 9, 2008 at 4:48 pm
maybe i'm just misreading it, but you want to insert just 255 chars right?
CREATE PROCEDURE [dbo].[AddSystemEvent]
(
@ScannerID As Int,
@TimeDate DateTime,
@EventID As Int,
@EventDesc NVarchar(256)
)
AS
Begin
Insert Into tb_system_event
(Scanner_ID, Time_Date, Event_ID, Event_Description)
Values (@ScannerID, @TimeDate, @EventID, LEFT(@EventDesc,255))
End
Lowell
June 9, 2008 at 4:57 pm
Thanks !!!
Can you also tell me how to test this stored procedure?
June 9, 2008 at 5:04 pm
freephoneid (6/9/2008)
Hi,I've a column Event_Desc(255)nvarchar in a table. If I insert a record in it through stored procesure which is more than 255 chars, it gives error.
Can any one give me the code in stored proc format which will check if length of event_desc entered by user not more than 255 & that if it is it'll just accept first 255 chars & insert it into database.
I'm using SQL Server 2000.
Here is my existing stored proc:
CREATE PROCEDURE [dbo].[AddSystemEvent]
(
@ScannerID As Int,
@TimeDate DateTime,
@EventID As Int,
@EventDesc NVarchar(256)
)
AS
Begin
Insert Into tb_system_event
(Scanner_ID, Time_Date, Event_ID, Event_Description)
Values (@ScannerID, @TimeDate, @EventID, @EventDesc)
End
Appreciate any help!!!!
Thanks!!!
Replace @EventDesc NVarchar(256) with @EventDesc NVarchar(255). If you limit the input to only 255 character, you should not be requiring any extra functions.
June 9, 2008 at 5:54 pm
from Query analyzer or SQL 2005 Management Studio:
exec AddSystemEvent 12,'06/09/2008',-21,'Some Bad Event Occured that probably should not have.'
note the scanner id example i put in an arbitrary number of 12, and did something similar with The EventId (-21)
Lowell
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy