SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to identify the objects that are commented in the procedure


how to identify the objects that are commented in the procedure

Author
Message
Tushar Kanti
Tushar Kanti
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 522
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
Tushar Kanti
Tushar Kanti
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 522
I need to remove the commented part from the string extracted from syscomments.
bitbucket-25253
bitbucket-25253
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16299 Visits: 25280
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
Tushar Kanti
Tushar Kanti
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 522
Thanks Ron...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search