在sql server中如何將獲取日期和時間值賦值給變數

時間 2021-07-08 21:28:45

1樓:匿名使用者

可用如下方法:

declare @time datetime --定義變數select @time=getdate() --獲取當前日期時間並賦值給變數

print @time --輸入列印變數內容執行結果:

如果覺得顯示不方便,可將時間型別的內容進行轉換,儲存過程寫法可改為:

declare @time varchar(20)select @time=convert(varchar(20),getdate(),120)

print @time

輸出結果如下:

2樓:我要註冊和登入

--如果列dtime是時間型別(2010-04-10 16:38:00.000)

insert into tb (dtime) values (getdate());

--如果是字串(2010-04-10)

insert into tb (dtime) values (convert(varchar(10), getdate(), 120));

3樓:方清海

declare @date datetime

set @date=convert(varchar(10),getdate(),120)

sql server 儲存過程中怎麼將變數賦值

4樓:

/*sql server 儲存過程中怎麼將變數賦值*/--sql賦值語句

declare @test1 int

select @test1 = 111

set @test1 = 222

--sql函式賦值,假定count()是自定義函式declare @test2 int

select @test2 = count(*) from sys.sysobjects

--sql儲存過程賦值,直接傳參處理(類似c語言中的指標嗎)if object_id('sp_test') is not null drop procedure sp_test

gocreate procedure sp_test(@test int output)

asbegin

select @test = 999

endgo

declare @test3 int

exec sp_test @test3 outputselect @test3

drop procedure sp_testgo

5樓:匿名使用者

暈啊,你這個賦值辦法。。。哈哈哈哈。

select @companycode = comcode from t_company where comid = '000001'

如果是給變

量賦常量

select @companycode = 100 類似

6樓:匿名使用者

不用 into 的例子:

1>2>3> declare

4> @testvalue as varchar(20);

5> begin

6> set @testvalue = 'first test!';

7> print( @testvalue );

8> end;

9> go

first test!

7樓:匿名使用者

zhanghb_3722

怎麼可以複製別人的**來回答呢!當然,大家都是正確的

8樓:匿名使用者

lz 試試這個 把位置換換

select top 1 @引數=column from table where ...

9樓:

select @companycode = comcode from t_company where comid = '000001'

10樓:淳于建設汲媚

儲存過程裡參

數的預設值不能使用函式,所以不能在儲存過程裡直接把引數的預設值設定為當前系統時間,不過可以在儲存過程裡賦值。還有一點疑問,既然@myday是當前系統時間了,為什麼還要做成引數呢?

create

procedure

pro_test

@myday

char(10)

asset

@myday=convert(char(10),getdate(),21)

update

mytable

setstatus=1

where

day>@myday

go@myday不為引數時可以這麼寫

create

procedure

pro_test

asdeclare

@myday

char(10)

set@myday=convert(char(10),getdate(),21)

update

mytable

setstatus=1

where

day>@mydaygo

sqlserver中,從表中查出一個空值,賦值給一個變數,這個變數到底是什麼?是null還是""還是其他的?

11樓:匿名使用者

@ad不是null也不是「」就是空值!!

12樓:匿名使用者

daclare @ad varchar(10);

select @ad=name from tb_stu where sid=-1;--資料表tb_stu存在,name也存在

--但是sid都是大於0的資料

if(@ad is null)

print '這是null';

else if(@ad='')

print 『這是單引號';

else

print '其他的'

@ad=null是錯誤的寫法

其實用一樓的說對的,

13樓:匿名使用者

set @name=null

14樓:

用exists判斷吧

if exists(select name from tb_stu where sid=-1)

else

在SQL Server資料庫中,如何將某

建立表的時候,把這一列設為int型,然後把標識這一個選成是,就可以自動編號了。如果使用語法建立 create table 表名字 自增列名字 int identity 1,1 not null 其他列 你的問題感覺就是改變 增刪改 表的結構而已。alter table 表名 add 列名 型別 增加...

在excel中,如何將0,1,2,3,4,5,6,7,8,9隨即的排列在一起行成21為的新資料

在a1單元格輸入 0123456789 在其他格中用下面公式 這個公式是重複了21次 mid a1,int rand 14 1 1 用vb實現,找個vb高手給你做吧。 人事行政共享店 用函式 rangd 和連結符號是可以解決的...

如何將中所有單位改為上標,如何將word中所有單位改為上標?

這個容易,你用滑鼠拉黑後面的數字,用右鍵在拉黑的範圍內開啟一個選單,點字型,會再出現一個選項框來,在效果那一欄就能找到上標 前面有個選框 你點選,再按確定,數字就變成了上標了,如果有很多要改上標的話,雙擊格式刷工具 單擊只能改一個數字,雙擊可以改多個數字 刷黑那個已經改為上標的數字,再去刷其他需要改...