August 3, 2010 at 8:46 am
I am working with SQL Server 2000. I am using the syscomments table to extract the procedure into string. In my project there are some conventions for objects so using string operations I am able to identify the objects used in the procedure. The issue is some of the objects are lying in the commented area of the procedure. Is there a way in which I can identify the code that is commented in the procedure so that I can identify the objects that are lying in the commented area.
Thanks,
Tushar
August 3, 2010 at 9:18 am
I need to remove the commented part from the string extracted from syscomments.
August 3, 2010 at 9:50 am
Lines can be comented by using -- (for a single line of text) or /* */
The @Script holds the text you retrieved from the syscomments entry and is used here to demonstrate the code
Here is some code to handle the -- case
SET @Script = 'DECLARE @S INT /* used to test for comment lines */
-- Another method to comment line
SELECT * FROM logentries'
DECLARE @Pos1 INT
DECLARE @Pos2 INT
SET @Pos1 = 0
SET @Pos2 = 0
SET @Pos1 = CHARINDEX('--',@Script,1)
IF @Pos1 > 0
BEGIN
SET @Pos2 = CHARINDEX(CHAR(10),@Script,@Pos1 + 1) --CHAR(10) = line feed
END
--Follwing code is to demonstrate what was retrieved
SELECT SUBSTRING(@Script,@Pos1,@Pos2 - @Pos1
Result:
-- Another method to comment line
In a similiar fashion you can use /* to find @Pos1 and for @Pos2 use '*/'
instead of CHAR(10)
August 3, 2010 at 10:10 pm
Thanks Ron...
Viewing 4 posts - 1 through 4 (of 4 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