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.
| Author |
Topic |
|
hamihami5
Starting Member
1 Post |
Posted - 2001-03-08 : 03:05:50
|
| Hey, you little (larges too) SQL hunters (and blood suckers... :) )your wishes come true.Dreamed something like nice script for retrieving given DML -clause from given db, given table, with single line command, tiered to figure out what we have on that table columns ?Well, just passing couple arguments to a proc(edure), you can do it.With that command, you create ready script and you paste it into your code ... or you can run it to get all the data you want without have to know your columns.Well, with dynamic SQL and sp_executesql.Nice feature?Passing metadata information to your proc, you can get specific rows with specific criteria just with a single line...by using info_schemas on system tables...Example: passing constraints to WHERE -part of the query, you get your SQL -engine constructed ready query :EXEC sp_c @dmL = 'SELECT', @db = 'pubs', @tbl = 'authors', @cri = '@', @exe = 1-->SELECT <columns> FROM <given_db_table> WHERE <primary_key_column> = @<primary_key_column> (or it can be a given value from primarykey column...well, you have to know the data)Of course, you need appropriate privileges for that base and table...Well,its under optimizing...and more specific JOIN operations could be under consideration too.-hami |
|
|
|
|
|
|
|