gpt4 book ai didi

sql插入到带有选择案例值的表中

转载 作者:行者123 更新时间:2023-12-03 14:41:35 24 4
gpt4 key购买 nike

出于某种原因,我对这个声明有问题

Insert into TblStuff
(FullName,Address,City,Zip)

Select
Case
When Middle is Null Then Fname + LName as FullName,
Else Fname +' ' + Middle + ' '+ Lname as FullName,
End
Case
When Address2 is Null Then Address1 as Address,
else Address1 +', ' + Address2 as Address,
End
City as City,
Zip as Zip
from tblImport

我在关键字“as”附近得到错误的语法

编辑添加到这个问题,让我知道我是否需要添加新帖子。

我知道下面的陈述有点不同,但是你能做一个类似于下面的案例陈述吗?下面的陈述甚至有意义吗?
Insert into TblStuff
(NickName,FirstName,MiddleName,Suffix)

Case when FirstName IS NULL then
NickName as Nickname,
IsNULL(FirstName,'''') as FirstName,
IsNULL(MiddelName,'''') as MiddleName,
IsNULL(NameSuffix,'''') as Suffix,
Else
IsNull(NickName2,'''') as NickName,
IsNULL(FirstName,'''') as FirstName,
IsNULL(MiddelName,'''') as Middlename,
Case when NameSuffix2 is NULL then
IsNULL(NameSuffix,'''')as suffix,
Else
IsNULL(NameSuffix,'''') + '''', '''' + IsNULL(NameSuffix2,'''') as suffix,
End
End
From tblImport

最佳答案

您需要在 end 后面加逗号完成案例陈述。并且,“as”在 case 之后声明,而不是在里面:

Insert into TblStuff(FullName, Address, City, Zip)
Select (Case When Middle is Null Then Fname + LName
Else Fname +' ' + Middle + ' '+ Lname
End) as FullName,
(Case When Address2 is Null Then Address1
else Address1 +', ' + Address2
End) as Address,
City as City,
Zip as Zip
from tblImport

关于sql插入到带有选择案例值的表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15820405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com