Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get Record Names?

Author  Topic 

sandeep43
Starting Member

11 Posts

Posted - 2011-08-16 : 21:38:05
Hi

My doubt is when i pass a sql string as input, i should get all record names present in the sql string passed, is there any logic that we can do to get this, please help me out


Regards
Sandeep

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-16 : 21:41:24
what do you mean by "record name" ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-08-16 : 22:21:19
Hi

Select * from PS_JOB A, PS_INSTALLATION B

PS_JOB and PS_INSTALLATION are Record Names, like this i want to extract only Record Names present when i pass the statement as input
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-16 : 22:23:36
you will need to do your own string parsing. It will not be easy.

Any special reason why do you need to do this ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-08-17 : 00:02:08
hi

Yea, its just requirement what we have got and it is necessary for us to get Record Name information from the sql string what we pass


Regards
Sandeep
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-17 : 00:14:41
well .... as i said earlier . . . it is not going to be easy.

You will need to use string manipulation function like charindex(), substring() to get what you want.

Your starting point will be the "FROM" keyword. There are so many style of writing a query that the table name (or what you refer to as "Record Names") will appear in multiple section of the query.

All i can say is Good Luck.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-08-17 : 00:21:05
Hi

Gud luck was also told by manager, anyways thanks for help i new i had to use substring, but how can determine end point after Table Name is written, it can be followed by either where or group by or order by or as anything like that, how can check?

Sandeep
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-17 : 00:25:44
typically you look for a SPACE or COMMA.

Things can be much more complicated if the table name contain space.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-17 : 00:48:30
Don't forget outer queries such as CROSS/OUTER APPLY, INNER/LEFT/RIGHT/FULL JOIN, correlated subqueries etc etc.
And how about table names used in functions?

This is nothing to do in SQL Server. Haev someone write a SQLCLR parser for you.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -