除了在CONVERT函数中包装我的文字之外,有没有办法指定我想要的文字,例如12345表示为BIGINT而非INT?在C#中,我可以指定12345L,但我不知道T-SQL中的等效功能。
答案 0 :(得分:3)
select cast(1 as bigint)
如果您只是投射您的价值。会是什么目的?
答案 1 :(得分:3)
您必须明确声明或强制转换为bigint。
虽然有prefixes and symbols for some other datatypes(二元,浮点数,金钱等),我不认为有一种方法可以在T-SQL中为bigint执行此操作,但不涉及明确声明bigint或者转换/转换它。
事实上,至少对于select...into
操作,一旦你的整数文字超出可以存储在int中的数据,SQL Server将使用数字(十进制)数据类型。
select 2000000000 as col into test;
select * from information_schema.columns where table_name = 'test';
-- DATA_TYPE: int
drop table test;
select 3000000000 as col into test;
select * from information_schema.columns where table_name = 'test';
-- DATA_TYPE: numeric
drop table test;
select cast(3000000000 as bigint) as col into test;
select * from information_schema.columns where table_name = 'test';
-- DATA_TYPE: bigint
drop table test;
declare @col bigint = 3000000000;
select @col as col into test;
select * from information_schema.columns where table_name = 'test';
-- DATA_TYPE: bigint
drop table test;
答案 2 :(得分:2)
declare @var as bigint
set @var = 12345
答案 3 :(得分:0)
您可以使用十进制或十六进制文字,如:
declare @variable bigint
set @variable = 0x7FFFFFFFFFFFFFFF
select @variable
set @variable = 9223372036854775807
select @variable