Sql 从插入脚本中提取值
我有一个插入脚本,试图从中提取值 这是剧本Sql 从插入脚本中提取值,sql,sql-server,insert,Sql,Sql Server,Insert,我有一个插入脚本,试图从中提取值 这是剧本 @scriptprod=INSERT intoProducts_Details ( VAL_ID , ProductID , SONumber , ProductTypeName , QuantitySold , Hours , Comments , Synch_Status ,
@scriptprod=INSERT intoProducts_Details
( VAL_ID ,
ProductID ,
SONumber ,
ProductTypeName ,
QuantitySold ,
Hours ,
Comments ,
Synch_Status ,
ProdID
)
VALUES ( 'V420131010213137TEST' ,
'186' ,
'5000000010' ,
'Bundled Anesthesia' ,
'9' ,
'12.00' ,
'test anas' ,
'' ,
'PD20131011121909999000'
)
我试过用like
substring(
@scriptprod,
charindex('PD20',@scriptprod,0),
LEN(@scriptprod)-CHARINDEX('PD20',@scriptprod,0)-1)
我没有得到请帮助如果我正确得到了您的问题,那么您希望在插入后返回一个值。我想你正在寻找这样的东西:-
OUTPUT Inserted.ID
即
你也可以检查一下
返回中插入到标识列中的最后一个标识值
同样的范围。作用域是一个模块:存储过程、触发器、,
函数或批处理。因此,如果
它们位于同一存储过程、函数或批处理中
您可以使用SCOPE\u IDENTITY尝试此操作
编辑:-
如果您想从数据库中获取一些值,那么可以使用简单的select命令
select * from table where id = 186;
或者如果要在插入操作完成之前得到值,则必须将整个值视为VARCHAR,然后搜索所需的字符串! 不,我需要从insert查询中获取值,例如,从上面的量纲查询中,我需要获取186,这是ProductID值。我理解您的观点。请看,我正在从.net应用程序在sql server中发送数千个insert脚本。我需要从应用程序传递的insert脚本中捕获这些产品id值。从这个查询中,我只需要提取产品id。希望您理解我的观点
Insert intoProducts_Details (VAL_ID,ProductID,SONumber,ProductTypeName,QuantitySold,Hours,Comments,Synch_Status,ProdID)
OUTPUT Inserted.ID
Values ('V420131010213137TEST','186','5000000010','Bundled Anesthesia','9','12.00','test anas','','PD20131011121909999000')
@scriptprod = SELECT SCOPE_IDENTITY()
select * from table where id = 186;