如何在 T-SQL 中指定 BIGINT 文字?
How to specify a BIGINT literal in T-SQL?
除了将我的文字包装在 CONVERT 函数中之外,有没有办法指定我想要的,例如12345 表示为 BIGINT 而不是 INT?在 C# 中,我可以指定 12345L,但我不知道 T-SQL.
中的等效功能
declare @var as bigint
set @var = 12345
您可以使用十进制或十六进制文字,例如:
declare @variable bigint
set @variable = 0x7FFFFFFFFFFFFFFF
select @variable
set @variable = 9223372036854775807
select @variable
select cast(1 as bigint)
IOW 你只需投出你的价值。目的是什么?
您必须显式声明或转换为 bigint。
虽然有 prefixes and symbols for some other datatypes(二进制、浮点数、货币等),但我认为没有办法在 T-SQL 中为 bigint 做到这一点涉及显式声明 bigint 或 casting/converting。
事实上,至少对于 select...into
操作,SQL 服务器将在您的整数文字超出 int 中可以存储的范围后使用数字(十进制)数据类型。
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;
除了将我的文字包装在 CONVERT 函数中之外,有没有办法指定我想要的,例如12345 表示为 BIGINT 而不是 INT?在 C# 中,我可以指定 12345L,但我不知道 T-SQL.
中的等效功能declare @var as bigint
set @var = 12345
您可以使用十进制或十六进制文字,例如:
declare @variable bigint
set @variable = 0x7FFFFFFFFFFFFFFF
select @variable
set @variable = 9223372036854775807
select @variable
select cast(1 as bigint)
IOW 你只需投出你的价值。目的是什么?
您必须显式声明或转换为 bigint。
虽然有 prefixes and symbols for some other datatypes(二进制、浮点数、货币等),但我认为没有办法在 T-SQL 中为 bigint 做到这一点涉及显式声明 bigint 或 casting/converting。
事实上,至少对于 select...into
操作,SQL 服务器将在您的整数文字超出 int 中可以存储的范围后使用数字(十进制)数据类型。
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;