mssql:插入语法 [英] mssql: insert into syntax

查看:86
本文介绍了mssql:插入语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

任何人都可以帮助我从访问中翻译它以便它可以在mssql中工作

(我需要获得下一个值,但不能使用身份,就像行一样被删除,

另一个必须获得新的下一个列号,这与删除的一个相同)

访问;

INSERT INTO表

SELECT

(IIF(代码<> Null,MAX(代码)+1,1)AS代码,

0 AS用户代码

FROM table


我在mssql中尝试了这个但是无法工作:

INSERT INTO表

SELECT

CASE

当代码为空时那么1

ELSE MAX(代码)+1

结束

AS代码,

0 AS用户代码

FROM table

Hello
Can anyone help me translate this from access so that it can work in mssql
(i need to get next value, but cannot use identity as if row is deleted,
another must get new next column number which would be same as deleted one)
Access;
INSERT INTO table
SELECT
(IIF(code<>Null,MAX(code)+1,1) AS code,
0 AS usercode
FROM table

I tried this in mssql but will not work:
INSERT INTO table
SELECT
CASE
WHEN code IS NULL THEN 1
ELSE MAX(code)+1
END
AS code,
0 AS usercode
FROM table

推荐答案

你好


您最好使用标识列。不能保证

连续但通常是所需的序数值。这是

类似于访问中的自动增量数e主题身份

(财产)在线图书获取更多信息。


John

" Andre" < SP ** @ spam.com>在消息新闻中写道:de ********** @ ss405.t-com.hr ...
Hi

You may be better of using an identity column. It is not guaranteed to be
contiguous but usually is the ordinal value that is required. This is
similar to the autoincrementing number in access. See the topic "Identity
(Property)" in books online for more information.

John
"Andre" <sp**@spam.com> wrote in message news:de**********@ss405.t-com.hr...
你好
任何人都可以帮助我从访问中翻译这个以便它可以在mssql中工作
(我需要获取下一个值,但不能使用身份,就像删除行一样,
另一个必须获得新的下一个列号,这与删除的相同
一个)
访问;
INSERT INTO表
SELECT
(IIF(代码<> Null,MAX(代码)+1,1)AS代码,
0 AS用户代码
从表格

我在mssql中尝试了这个但是无法工作:
INSERT INTO表
SELECT
CASE
当代码为空时那么1
ELSE MAX(代码)+1
END
AS代码,
0 AS用户代码
FROM table
Hello
Can anyone help me translate this from access so that it can work in mssql
(i need to get next value, but cannot use identity as if row is deleted,
another must get new next column number which would be same as deleted
one)
Access;
INSERT INTO table
SELECT
(IIF(code<>Null,MAX(code)+1,1) AS code,
0 AS usercode
FROM table

I tried this in mssql but will not work:
INSERT INTO table
SELECT
CASE
WHEN code IS NULL THEN 1
ELSE MAX(code)+1
END
AS code,
0 AS usercode
FROM table



On Sun,2005年8月21日11:02:42 +0200,Andre写道:


(snip)
On Sun, 21 Aug 2005 11:02:42 +0200, Andre wrote:

(snip)
访问;
INSERT INTO表
SELECT
(IIF(代码<> Null,MAX(代码)+1,1)AS代码,
0 AS用户代码
FROM table
Access;
INSERT INTO table
SELECT
(IIF(code<>Null,MAX(code)+1,1) AS code,
0 AS usercode
FROM table




嗨安德烈,


访问调用" ;自动编号)。


如果有理由'为什么你不能使用IDENTITY,那么使用


SELECT COALESCE( MAX(代码),0)+ 1 AS代码

FROM table


Best,Hugo

-


(删除_NO_和_SPAM_以获取我的电子邮件地址)



Hi Andre,

As John says: Consider using IDENTITY (the SQL Server equivalent of what
Access calls "autonumber").

If there are reason''s why you can''t use IDENTITY, then use

SELECT COALESCE(MAX(code), 0) + 1 AS code
FROM table

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


将尝试这个

thx


(顺便说一句,我提到我不能使用身份,因为它不会保留

正确的顺序如果中间行被删除

并且它不允许最终用户改变它。

Hugo Kornelis < hugo@pe_NO_rFact.in_SPAM_fo>在消息中写道

news:6f ******************************** @ 4ax.com ...
will try this
thx

(by the way, i mentioned I cannot use identity as it would not preserve
correct order if a middle row is deleted
and it would not allow end-user to change it)
"Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message
news:6f********************************@4ax.com...
On Sun,2005年8月21日11:02:42 +0200,Andre写道:


如果有理由'你为什么可以不使用IDENTITY,然后使用

SELECT COALESCE(MAX(代码),0)+ 1 AS代码
FROM table
On Sun, 21 Aug 2005 11:02:42 +0200, Andre wrote:

If there are reason''s why you can''t use IDENTITY, then use

SELECT COALESCE(MAX(code), 0) + 1 AS code
FROM table



这篇关于mssql:插入语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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