August 19, 2016 at 5:59 pm
Anyone can help me .
Is it possible to do this ..
DECLARE
@ProjectCode varchar(25),
@TypeCodevarchar(25),
@BomDatevarchar(25),
SET @ProjectCode='PRO000001'
SET @TypeCode='PS0000001'
EXEC ('
INSERT INTO [dbo].[zPS-XSCN231L] (
[level],
[Pin],
[Description]
)
VALUES (
@ProjectCode,
@TypeCode,
@BomDate
)
')
August 20, 2016 at 3:11 am
Not with EXEC, but you can use sp_executesql to execute strings with parameters.
That said, there's absolutely no need for dynamic SQL in the code you posted. This is equivalent and works without any exec needed.
DECLARE
@ProjectCode varchar(25),
@TypeCodevarchar(25),
@BomDatevarchar(25),
SET @ProjectCode='PRO000001'
SET @TypeCode='PS0000001'
INSERT INTO [dbo].[zPS-XSCN231L] (
[level],
[Pin],
[Description]
)
VALUES (
@ProjectCode,
@TypeCode,
@BomDate
)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply