2

As an example I have this query here

SELECT DISTINCT convert(varchar(10), PickupDate ,105) AS [Pickup dates]
FROM info.dbo.A_Query_Detail AS D
INNER JOIN info.dbo.A_Query_Header AS ACQ on ACQ.ID = D.Header_ID
WHERE D.HeaderID = @HeaderID 
AND ACQ.PriceType = 'Pickup'
GROUP BY 
Adrid, convert(varchar(10), PickupDate ,105) 

What I want to get here is only the column name without it conflicts with the above query. So my result would be something like: "Column_Date" or Pickup dates as stated above. I have red something about sys.tables but I can't seem to make it work with the above code.

3
  • 1
    I don't really get your question, you'll have one column, called [Pickup dates] and it will be VarChar(10). Commented Nov 13, 2014 at 12:34
  • I just want the column name without the dataset Commented Nov 13, 2014 at 12:37
  • This is not volatile data, its predictable unless you use *. Commented Nov 13, 2014 at 12:42

2 Answers 2

3

If you want a list of columns, sometimes I use a temporary view:

create view _MyView as <your query here>

Then you can do:

select *
from information_schema.columns
where table_name = '_MyView'

You can get the column names and types by doing this.

Then you can do:

drop view _MyView

(And, of course, the view name should not conflict with anything else.)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you gordon I will try this and get back to you!
@MishMish, if you have to specify <your query here>, why not do my answer? stackoverflow.com/a/26909275/659190
@Jodrell your answer is also good but have not tried it, actually the whole solution need to be changed anyways, It's more advanced then I thought I might upload a new question for help later. It's a bit complicated :-)
1

try this,

SELECT 'Pickup dates' AS [ColumnName];

this is like @Gordon Linoff's answer but doesn't carry the overhead of creating a view.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.