November 6, 2018 at 5:32 am
Folks:
I need help with a query. I have a column in which we store the stored procedures executed history with the parameters passed. I want to parse the data and get only the stored procedure names from the column.
exec spname1 867, "name"
exec spname2 "mgr"
exec spname1 678, "name2"
exec spname3 "John", "Dan", 6456
exec spname1 4567, "test"
I want the Output to be:
exec spname1
exec spname2
exec spname1
exec spname3
exec spname1
Thanks!
November 6, 2018 at 5:39 am
Hi,
As you are using SQL 2017 forum, you can make use of STRING_SPLIT() function passing ' ' as the delimiter I think.
https://docs.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql?view=sql-server-2017
Thanks.
November 6, 2018 at 5:39 am
sqldba20 - Tuesday, November 6, 2018 5:32 AMFolks:I need help with a query. I have a column in which we store the stored procedures executed history with the parameters passed. I want to parse the data and get only the stored procedure names from the column.
exec spname1 867, "name"
exec spname2 "mgr"
exec spname1 678, "name2"
exec spname3 "John", "Dan", 6456
exec spname1 4567, "test"I want the Output to be:
exec spname1
exec spname2
exec spname1
exec spname3
exec spname1Thanks!
This should get you going
DECLARE @SAMPLE VARCHAR(100) = 'exec spname2 "mgr"';
SELECT LEFT(@SAMPLE,CHARINDEX(CHAR(32),@SAMPLE,6) - 1);
Outputexec spname2
Viewing 3 posts - 1 through 2 (of 2 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