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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic SQL

Author  Topic 

bvsrameshbabu
Starting Member

3 Posts

Posted - 2007-07-20 : 09:22:34
Can anybody help me in writing Dynamic Sql queries on different tables using information schemas or sysobjects. I want to write a query in a database using different tables which have relations.

Ramesh

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-20 : 09:26:46
What have you tried so far ?
Post your query here with the table DDL, sample data and expected result


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

Go to Top of Page

bvsrameshbabu
Starting Member

3 Posts

Posted - 2007-07-20 : 09:52:06
Thank you for your reply.

Actually, I want to write the Dynamic Query in a database for each and every table. For example I have a database EMPDB which contains tables tblEmployeeDetails, tblDepartment and tblSalary. I have prepared an user interface to retrieve tables from database, upon selection of the table, user will be able to select the fields from different tables.

for instance user can select EMPName from tblEmployeeDetails, DeptName from tblDepartment and BasicSalry from tblSalary.
These already have relations.

For this I need to generate the query.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-07-20 : 10:57:29
Search 'dynamic sql' in books online for sample code.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-20 : 11:06:02
take a look here http://www.sommarskog.se/dynamic_sql.html


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

Go to Top of Page

bvsrameshbabu
Starting Member

3 Posts

Posted - 2007-07-23 : 01:16:26
Dear Mr. Khtan,

Thank you for your response. I have checked out the URL suggested by you.

I want to know one more thing i.e., can we know the the relationships assigned to tables in a database. In my previous example the employee table contains the Department ID as Foreign Key of Department Table.

Basically, I want to know all the Primary Keys and Foreign Keys in a database, so that I can write the joins accordingly.

Thanking you,
Ramesh
Go to Top of Page
   

- Advertisement -