将输出存储在参数中 [英] Storing output in a parameter

查看:80
本文介绍了将输出存储在参数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示当天。如何将输出值存储在参数''@getdate''中?



I want to show current day. How do you store output value in a parameter ''@getdate''?

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





在Microsoft SQL Server 2008中工作,

这是正确的吗?



请提前帮助和谢谢。



Working in Microsoft SQL server 2008,
Is this correct?

Please help and thanks in advance.

推荐答案

是和否。这取决于你想要什么。



NO:@getdate不是一个参数,它将是一个变量

NO:在同一个上下文中声明一个与函数同名的变量是不明智的

是:你可以声明并使用变量

是:你可以存储变量中函数的输出

是:您可以检索此类函数的值,如下所示: select getdate()

YES:您可以将函数的输出存储在变量中:声明@date datetime;设置@date = getdate();选择@date ;

是:您可以从日期中检索DAY值

YES。你甚至可以在daytime变量中存储一天的值,但这是无稽之谈。



所以,这样看起来会更好:

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:
declare @date int
set @date = DAY(getdate())
select @date


您好朋友,



阅读以下链接...



你会得到一些想法数据类型和变量。

数据类型(Transact-SQL) [ ^ ]

SQL SERVER 2008 - 2012 - 在单个语句中声明和分配变量 [ ^ ]

SQL Server 2008中的表值参数 - VB.NET [ ^ ]

SQL Server中的全局变量 [ ^ ]



问候,

GVprabu
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


这篇关于将输出存储在参数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆