Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to give Current Date as Alias name.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2010-07-24 : 01:11:24
Dear All,

I am having following queary and output,

SELECT PI.REVENUE AS SECOND_REVENUE FROM SA.A_PERFORMANCEINVESTIGATION PIINNER JOIN SA.D_DATE DT ON PI.DATEID = DT.DATE_ID
WHERE TO_CHAR(DT.FULL_DATE,'DD/MM/YYYY') = (select TO_CHAR(sysdate-1,'DD/MM/YYYY') from dual)

Output:
SECOND_REVENUE
120978

I want output as follows, means i want to column name as current date.
Output:
24-07-2010
120978

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-24 : 02:34:30
try this:


declare @string char(30)
set @string = quotename(replace(convert(varchar(10),getdate(),102),'.','_'))
print @string

declare @sql nvarchar(200)
set @sql = 'select 1234 as ' +@string
exec sp_executesql @sql

Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2010-07-24 : 02:44:14
Dear slimt_slimt,

But i am using single queary, i am not using store procedure.
Is it possible with single queary.

thnks
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-07-24 : 03:41:39
Whatever you do in stored procedure
you can use it inline.
As if you are passing some parameters to procedure
You will have to declare it and have to set its value at the top of Stored procedure code.
so can use above code inline definitely..

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-24 : 03:42:06
are you using SQL Server or Oracle ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2010-07-24 : 04:49:03
Dear khtan,

I am using Oracle 10g.

thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-24 : 05:57:36
quote:
Originally posted by hspatil31

Dear khtan,

I am using Oracle 10g.

thanks



Then you should be posting at a Oracle forum. You might have not aware that that you have posted in "General SQL Server Forum" - "New to SQL Server Programming". SQLTeam.com is on Microsoft SQL Server


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-26 : 08:57:26
Post your question at www.orafaq.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -