如何在Sql Query中减去nvarchar值? [英] How to subtract nvarchar values in Sql Query?
问题描述
我有一个查询生成以下字符串,我想用1增加最后一个值...任何人都建议我这样做。
< pre lang =sql> BEGIN
声明 @count int
选择 @count = count(*)来自 StudentPersonalInformation
if (@count = 0)
开始
声明 @ var1 nvarchar ( 50 )
选择 @ var1 = ' 1000'
SELECT @ var1 =注册rationNumber
FROM StudentPersonalInformation
SELECT 转换( nvarchar ( 50 ),YEAR(GETDATE()), 107 )+ ' /' + @ var1 AS ' Reg_No';
end
else
选择 RegistrationNumber 作为 CurrentYear 来自 StudentPersonalInformation
结束
CurrectYear
2014/1000
我希望增加如下......
2014/1001
2014/1002
2014/1003等
如果您觉得需要在nvarchar
的减法操作中,这是一个明确的表明您创建了错误的数据库架构。每当您需要任何普通算术时,您需要使用其中一种数字类型。
-SA
I have a query which generates the following string and i want to increment the last value with 1...can anybody suggest me to do this.
BEGIN
declare @count int
select @count = count(*)from StudentPersonalInformation
if(@count=0)
begin
declare @var1 nvarchar(50)
select @var1='1000'
SELECT @var1 = RegistrationNumber
FROM StudentPersonalInformation
SELECT Convert(nvarchar(50),YEAR(GETDATE()),107)+'/'+@var1 AS 'Reg_No';
end
else
select RegistrationNumber as CurrentYear from StudentPersonalInformation
END
CurrectYear
2014/1000
and i want to increment like the following...
2014/1001
2014/1002
2014/1003 etc
If you feel a need in subtraction operation onnvarchar
, this is a clear indication that you create wrong database schema. Whenever you need any ordinary arithmetic, you need to use one of the numeric types.
—SA
这篇关于如何在Sql Query中减去nvarchar值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!