Re: Meta data of query?
From: Dan Guzman (danguzman_at_nospam-earthlink.net)
Date: 07/11/04
- Next message: Joe Celko: "Re: Selecting Data in a While Loop"
- Previous message: Steve Kass: "Re: Partitioned views"
- In reply to: LCaffrey: "Meta data of query?"
- Next in thread: LCaffrey: "Re: Meta data of query?"
- Reply: LCaffrey: "Re: Meta data of query?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 11 Jul 2004 09:28:15 -0500
To add to David's response,
> Is it possible to access this meta data in the executing script from
> any of the sys tables. Would it be easier to parse the SQL statement.
>
> Also, where is the meta-data of a result set of a stored procedure
> stored or where or how is it obtained.
Column meta data is not persisted for ad-hoc queries and SQL statement
parsing is not trivial. However, meta data is returned to the client along
with the resultset and you can easily access it from you application (this
is what QA does).
Although you can get resultset meta data directly in Transact-SQL, one
workaround is to create a temp table with the result so that you can query
the temp table meta data that corresponds to the resultset. The example
below uses this technique along with SET FMTONLY as David suggested.
IF OBJECT_ID('tempdb..#MetaData') IS NOT NULL
DROP TABLE #MetaData
--create temp table with resultset columns
SELECT *
INTO #MetaData
FROM
OPENROWSET (
'SQLOLEDB' ,
'Trusted_Connection=Yes;Database=tempdb',
'SET FMTONLY ON SELECT * FROM personal_details SET FMTONLY OFF'
)
--list meta data
SELECT *
FROM tempdb.INFORMATION_SCHEMA.COLUMNS
WHERE
OBJECT_ID(QUOTENAME('dbo') + '.' + QUOTENAME(TABLE_NAME)) =
OBJECT_ID('tempdb.dbo.#MetaData')
ORDER BY ORDINAL_POSITION
DROP TABLE #MetaData
-- Hope this helps. Dan Guzman SQL Server MVP "LCaffrey" <lxc@eosys.ie> wrote in message news:4a6dded0.0407110314.7a79902@posting.google.com... > Hi, > > Take a typical query... > > SELECT col1 as "my_first_name" > ,col2 as "my_second_name" > ,col3 as "my_telephone_no" > FROM personal_details > WHERE col2 = 'Caffrey' > > When this is run in Query Analyzer or the SQL Window of EE, the column > headers are automatically given in the result set. > > Is it possible to access this meta data in the executing script from > any of the sys tables. Would it be easier to parse the SQL statement. > > Also, where is the meta-data of a result set of a stored procedure > stored or where or how is it obtained. > > Regards > > Liam Caffrey > lxc@eosys.ie
- Next message: Joe Celko: "Re: Selecting Data in a While Loop"
- Previous message: Steve Kass: "Re: Partitioned views"
- In reply to: LCaffrey: "Meta data of query?"
- Next in thread: LCaffrey: "Re: Meta data of query?"
- Reply: LCaffrey: "Re: Meta data of query?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|