Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to show current day. How do you store output value in a parameter '@getdate'?

SQL
declare @getdate datetime 
set @getdate =day(getdate())


Working in Microsoft SQL server 2008,
Is this correct?

Please help and thanks in advance.
Posted
Updated 11-Mar-13 10:37am
v5
Comments
Sergey Alexandrovich Kryukov 11-Mar-13 10:21am    
Please tag your language and platform.
—SA
[no name] 11-Mar-13 10:36am    
Okay.... did you try it? Did it work? If it worked then it's correct. I suspect this is not your real question.

Yes and no. And it depends on what you want exactly.

NO: @getdate won't be a parameter, it will be a variable
NO: it is not wise to declare a variable with the same name as a function in the same context
YES: you can declare and use variables
YES: you can store the output of a function in a variable
YES: you can retrieve value of such functions, like this: select getdate()
YES: you can store output of a function in a variable: declare @date datetime; set @date = getdate();select @date;
YES: you can retrieve DAY value from a date
YES. you can even store a day value in a datetime variable, but it is nonsense.

So, it would look better this way:
SQL
declare @date int
set @date = DAY(getdate())
select @date
 
Share this answer
 
v2
Comments
Biodude Basava 11-Mar-13 11:45am    
Thanks a lot Zoltan for guiding me,This is what i wanted.
Zoltán Zörgő 11-Mar-13 13:22pm    
I am glad I could help you. If this is what you wanted, feel free to accept my answer.
Hi Friend,

Read the following links...

you will get some Idea about Data types and variables.
Data Types (Transact-SQL)[^]
SQL SERVER 2008 – 2012 – Declare and Assign Variable in Single Statement[^]
Table-Value Parameters in SQL Server 2008 - VB.NET[^]
Global Variables in SQL Server[^]

Regards,
GVprabu
 
Share this answer
 
v2

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