Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to create an Excel report for my new company.

In it I have a complex task, in which i need to join 4-5 tables and also need to pivot a table (Transaction/Detail/Child table) then need to join it to already joined group.Due to this pivot number of out put columns varies (ie,the where clause uses a date range filtration,if the date filtration is bigger results more rows ,when pivot this rows number of columns are increased ,so number of columns are dynamic.) .From this out put, I need to remove the some columns(like primary/foreign keys) from out put.But i can't give the name list of columns in select clause since the number of columns(Also their name) are dynamic.

Even though this is my work, i can successfully handled up to the dynamic column name ,but now i want to remove unwanted columns . I am expecting something like below,

I have a table named MyTable with 5 columns as Column1,Column2,Column3,Column4 and Column5 .
Consider Column1 is primary key and Column2 is foreign key,Also assume i know the name of primary key and foreign key columns only (Column1,Column2)

I want to write a select query as below

Select *,Remove(Column1),Remove(Column2) from MyTable

i need output with 3 columns as Column3,Column4 and Column5

Thanks&Regards,
Aadyakumar.D.V
Posted
Comments
ArunRajendra 9-Jun-14 3:56am    
I would suggest just don't write those columns into excel.
Nelek 9-Jun-14 4:22am    
Aadyakumar 9-Jun-14 4:44am    
OK, it is a way ,it will give solution for my job , but i need to know how can we do it in Sql Server

any how,thanks for replay

What you want to do (exclude some preselected columns from a query) is not possible, simply because the TSQL language does not handle that.

I would suggest you keep your columns in the query, and just mask the unwanted columns in Excel.

Otherwise it would require just an indecent amount of spaghetti code that no one would ever want to have to deal with.

Good luck :)
 
Share this answer
 
Comments
Aadyakumar 9-Jun-14 6:22am    
Thanks for your suggestion , i am also planning to handle it in Excel . But i want to know, is it possible in Sql .
;)
Then just specify the column names you do want in your query:
SQL
SELECT Column3, Column4, Column5 FROM MyTable
 
Share this answer
 
Comments
Aadyakumar 9-Jun-14 4:53am    
But my problem is i don't know the columns name.because it is dynamic. I know only the key (primary and foreign key) columns name. ie,i know the column name Column1 and Column2,then how can i write the select for remaining column . Another thing don't go for sys.tables and columns because columns are dyanamic

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900