|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:59 AM
Points: 103,
Visits: 410
|
|
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
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:59 AM
Points: 103,
Visits: 410
|
|
| I need to remove the commented part from the string extracted from syscomments.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 5,099,
Visits: 20,190
|
|
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)
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please read Before posting a performance problem please read
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, April 25, 2013 7:59 AM
Points: 103,
Visits: 410
|
|
|
|
|