SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Column names
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/25/2012 :  13:51:38  Show Profile  Reply with Quote
I need to pre-map my next conversion in an excel sheet for the customer. What i would like to be able to do is take the column names in the relevant tables in our db and the column names in the corresponsding tables on the client's db and place those values as rows, adjacent to each other, (say, column A is our, column C is theirs. I can pull their column names easy enough by doing a "select * from" and copying the resultset with headers into a new excel sheet. I then delete the data from the excel sheet and leave the column names in place, do a pivot on the table in excel, and i have that part. The problem with the tables on our side is that they are empty. Therefore when i do a "select * from" on our tables, i get empty resultssets, but the resultset shows the column names. I cannot, however, do a "copy with headers" function on that resultset. Does anyone know of a quick and easy way to grab that data from an empty table so i can paste it in excel?

thanks.

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 04/25/2012 :  14:01:23  Show Profile  Visit webfred's Homepage  Reply with Quote
run

sp_help YourTableName

and see what you get


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/25/2012 :  14:05:14  Show Profile  Reply with Quote
i get a very cool list of column names in a single column all ready to be dropped into excel. thanks a ton.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 04/25/2012 :  14:08:12  Show Profile  Visit webfred's Homepage  Reply with Quote
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/25/2012 :  14:17:23  Show Profile  Reply with Quote
ok, but wait, this now gets a little more complex. On the client's db, i'm using the following script to pull the data i need from multiple tables:

SELECT 	* 
					FROM	PropertyReports pr, PropertyReportItems pri, CombinedDesc cd, CFSData cfs, CombinedDesc cf 
					WHERE	pr.ID = pri.PropertyReportID
					AND		pri.ClassID = cd.ID 
					AND		pr.CFSID = cfs.CFSID
					AND		cfs.CallTypeID = cf.ID
					
					ORDER BY pr.CFSID DESC



Because that data is coming from multiple tables, i can't use the sp_help command to get the same layout. So, when i try to use a "Select * into" command to dump the resultset of this query into a new table:


SELECT 	* INTO dbo.OffenseProperty
					FROM	PropertyReports pr, PropertyReportItems pri, CombinedDesc cd, CFSData cfs, CombinedDesc cf 
					WHERE	pr.ID = pri.PropertyReportID
					AND		pri.ClassID = cd.ID 
					AND		pr.CFSID = cfs.CFSID
					AND		cfs.CallTypeID = cf.ID
					
					ORDER BY pr.CFSID DESC



i run into problems because of the use of the ID column from two different tables (error says ID is already used in the new table, and not unique). What is my workaround to get this query dumped into a new table (i have other reasons for wanting to move that resultset into it's own table).

thanks again
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 04/25/2012 :  14:21:28  Show Profile  Visit webfred's Homepage  Reply with Quote
Your workaround is to not use * and write a column list instead and using aliases to avoid duplicate column names because they are not possible in a table.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/25/2012 :  14:23:07  Show Profile  Reply with Quote
wait a minute. disregard the previous for now. I see where i might need to use a union to get rid of the duplicate columns in my resultset.
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/25/2012 :  14:24:18  Show Profile  Reply with Quote
i see what you mean. thanks.
Go to Top of Page

robvolk
Most Valuable Yak

USA
15566 Posts

Posted - 04/25/2012 :  14:28:45  Show Profile  Visit robvolk's Homepage  Reply with Quote
There's also:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS

There's a lot of extra data in there you can remove if you don't need it.

And if you really want to mike life simple, you can tag your tables and columns with extended properties to indicate which external table/column they map to. You can then query them using sys.extended_properties.
Go to Top of Page

amitji.tspl
Starting Member

India
1 Posts

Posted - 04/27/2012 :  14:12:44  Show Profile  Reply with Quote
i am join 2 Excel file threw MS access and i need to file name in last column and each cell

Amit
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000