November 11, 2011 at 10:31 am
CODE
SELECT *
FROM OPENQUERY(test_TERADATA,
'select *
into #tlb_testfile
from databse.file
where
datacode=''49548''
;')
This code runs fine without the "into #tlb_testfile" line, but when I add the code I get the error:
[NCR][ODBC Teradata Driver][Teradata Database] Syntax error: INTO clause is not allowed. ".
I really need the temp table. What am I doing wrong?
I tried searching the internet, and couldn't find much about this error
Thanks
November 11, 2011 at 10:33 am
the INTO belongs outside of the openquery:
CODE
SELECT *
into #tlb_testfile
FROM OPENQUERY(test_TERADATA,
'select *
from databse.file
where
datacode=''49548''
;')
Lowell
November 11, 2011 at 10:43 am
Thank you so much. Now if I can piggyback a followup question about the same temp file...
I wanted to pull a list of column names from my temp file (and others as well and found the following code:
SELECT column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM information_schema.columns
WHERE table_name = '#tbl_temptable'
When I run the code, it brings up an empty table with column headers:
Column Name, Data Type, and maximum length which coincidently is the as statements in the code. Can you tell me what I am doing wrong here?
Thanks again
November 11, 2011 at 10:49 am
cljolly (11/11/2011)
Thank you so much. Now if I can piggyback a followup question about the same temp file...I wanted to pull a list of column names from my temp file (and others as well and found the following code:
SELECT column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM information_schema.columns
WHERE table_name = '#tbl_temptable'
When I run the code, it brings up an empty table with column headers:
Column Name, Data Type, and maximum length which coincidently is the as statements in the code. Can you tell me what I am doing wrong here?
Thanks again
'information_schema.columns' returns one row for each column that can be accessed by the current user in the current database. Whereas #Table sits in TempDB database.
November 11, 2011 at 10:51 am
cljolly (11/11/2011)
Thank you so much. Now if I can piggyback a followup question about the same temp file...I wanted to pull a list of column names from my temp file (and others as well and found the following code:
SELECT column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM information_schema.columns
WHERE table_name = '#tbl_temptable'
When I run the code, it brings up an empty table with column headers:
Column Name, Data Type, and maximum length which coincidently is the as statements in the code. Can you tell me what I am doing wrong here?
Thanks again
Empty Table / No rows returned?
November 11, 2011 at 10:54 am
Column_name Data_type Maximum Length
and the rest of it is blank.
Is there a way of displaying column names and data types from a table?
November 11, 2011 at 11:03 am
cljolly (11/11/2011)
Column_name Data_type Maximum Lengthand the rest of it is blank.
Is there a way of displaying column names and data types from a table?
I am not sure. Try this.
USE TEMPDB
GO
SP_HELP '#TBL_TEMPTABLE'
OR
USE TEMPDB
GO
SELECT COLUMN_NAME 'COLUMN NAME',
DATA_TYPE 'DATA TYPE',
CHARACTER_MAXIMUM_LENGTH 'MAXIMUM LENGTH'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '#TBL_TEMPTABLE'
November 11, 2011 at 11:32 am
i think the issue is related to teh name not being #tbl_temptable, but actually [#tbl_temptable[100underscores]0000000000F0]
for example. if you do this after you know your table exists :
SELECT table_name,
column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM tempdb.information_schema.columns
you will see the table name is not equal.
--edit--thois will get you what you are asking for:
SELECT table_name,
column_name 'Column Name',
data_type 'Data Type',
CHARacter_maximum_length 'Maximum Length'
FROM tempdb.information_schema.columns
WHERE table_name IN( SELECt name from tempdb.sys.tables WHERE object_id = object_id('tempdb..#tbl_temptable') )
the way i've always done it is with the SQL tables, and not the information_schemas:
select colz.name ,
type_name(colz.system_type_id),
colz.max_length,
*
from tempdb.sys.tables tabz
inner join tempdb.sys.columns colz
on tabz.object_id=colz.object_id
and tabz.object_id = object_id('tempdb..#tbl_temptable')
Lowell
November 14, 2011 at 11:18 am
Thank you!
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply