displaying parameter of the string in sql
I have a string as "dbo.proudction @prodid= '1,2,10,4,5,6,7,8,13,16,17,3' ,@stock= 0”.
I have to execute a query
to select '1,2,10,4,5,6,开发者_如何学Go7,8,13,16,17,3'.
If I understand correctly, you just want to do:
SELECT @prodid;
I am not really sure of what you are looking for but could this be what you are looking for:
SELECT * FROM YourTableName WHERE YourFieldName1 = @prodid and YourFieldName2 = @stock
I guess you want to extract the text between the quotes.
If the string in in a table you can do this
declare @T table(Col1 varchar(100))
insert into @T values ('dbo.proudction @prodid= ''1,2,10,4,5,6,7,8,13,16,17,3'' ,@stock= 0')
select
substring(Col1, Start, Stop-Start)
from @T
cross apply
(select charindex('''', Col1)+1) c1(Start)
cross apply
(select charindex('''', Col1, Start)) c2(Stop)
Slightly modified if the string is in a variable.
declare @str varchar(100)
set @str = 'dbo.proudction @prodid= ''1,2,10,4,5,6,7,8,13,16,17,3'' ,@stock= 0'
select
substring(Col1, Start, Stop-Start)
from (select @str) as T(Col1)
cross apply
(select charindex('''', Col1)+1) c1(Start)
cross apply
(select charindex('''', Col1, Start)) c2(Stop)
精彩评论