小编Sim*_*one的帖子

如果第一列在 SQL (MS SQL) 中为空/空,如何从第二列中选择值?

有人可以帮我构建一个 SQL 查询,如果 column1 为空/空,我应该从 column2 获取值,如果 column2 也是空/空,我应该从 column3 获取值。

下面是我正在使用的表格

Price1   Price2   Price3

120

          140

                 160
Run Code Online (Sandbox Code Playgroud)

我正在寻找的输出是

Price

120

140

160
Run Code Online (Sandbox Code Playgroud)

我已经试过了

select Price1 as Price
from A
WHERE PRICE1 IS NOT NULL
UNION
SELECT PRICE2 as Price
from A
where PRICE1 is null
UNION 
select PRICE3 as id
from A
where PRICE2 is null

select COALESCE (PRICE1,PRICE2,PRICE3) from A

select ISNULL(PRICE1,ISNULL(PRICE2,PRICE3)) from A

select 
case when PRICE1 IS not null then PRICE1 when PRICE1 IS null then …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

5
推荐指数
2
解决办法
5305
查看次数

Webservice - 如何在日期时间元素中传递时区信息

我得到了一个 wsdl,我必须按照它的规范创建一个 web 服务;我正在使用 Visual Studio 2010。其中还有这种复杂类型的定义:

    <xsd:complexType name="Person">
        <xsd:sequence>
            <xsd:element name="surname" type="xsd:string"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="birthDate" nillable="true" type="xsd:dateTime"/>
        </xsd:sequence>
    </xsd:complexType>
Run Code Online (Sandbox Code Playgroud)

使用 VS 我得到了以下 cs(我不记得我是怎么做的,但我遵循了网上的说明):

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://XXX/Submitter/")]
    public partial class Person {
        private string surnameField;
        private string nameField;
        private System.Nullable<System.DateTime> birthDateField;

        /// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string surname {
            get {
                return this.surnameField;
            }
            set {
                this.surnameField = value;
            }
        }
        /// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string name {
            get {
                return this.nameField;
            }
            set …
Run Code Online (Sandbox Code Playgroud)

c# datetime soap wsdl web-services

5
推荐指数
1
解决办法
3254
查看次数

在sql中查找字符串长度而不是从零开始

我有一个问题,我正在从excel(.csv)文件上传员工代码和帐号,我将检查员工代码并更新或插入相应员工代码的帐号.但是如果员工代码以"0"开头,则csv文件不会考虑0并且只发送剩余的字符,所以当我在sql中检查它时将与表数据(Employee Code)不匹配.

我有计划匹配他们,但我不知道该怎么做.

我试过下面的查询

declare @EmployeeCodeNET varchar(max)='MJ300'; 
declare @EmployeeCodeDB varchar(max)='00MJ300';


select LTRIM(REPLACE(@EmployeeCodeDB, '0', ''))--It should return 'MJ300'
Run Code Online (Sandbox Code Playgroud)

sql-server csv sql-server-2008

3
推荐指数
1
解决办法
804
查看次数

DELETE ... OUTPUT COUNT(DELETED.*)

我想知道在某个DELETE操作中删除了多少行.

我把微软例B

DELETE Sales.ShoppingCartItem
OUTPUT DELETED.* 
WHERE ShoppingCartID = 20621;
Run Code Online (Sandbox Code Playgroud)

并尝试修改它只返回count已删除的记录:

DELETE FROM datacache 
OUTPUT COUNT(DELETED.*)
WHERE userId=@id
Run Code Online (Sandbox Code Playgroud)

但这引发了

ExceptionMessage: "Incorrect syntax near '*'."
ExceptionType: "System.Data.SqlClient.SqlException"
Message: "Error"
Run Code Online (Sandbox Code Playgroud)

所以我试过了

DELETE FROM datacache 
OUTPUT COUNT(DELETED)
WHERE userId=@id
Run Code Online (Sandbox Code Playgroud)

哪个扔了

ExceptionMessage: "Invalid column name 'DELETED'."
ExceptionType: "System.Data.SqlClient.SqlException"
Message: "Error"
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

sql sql-server output-clause

2
推荐指数
2
解决办法
5990
查看次数

通用SQL问题

我有一张桌子A.

ID    Term
10    A
10    B
10    C
20    A
20    B
20    E
Run Code Online (Sandbox Code Playgroud)

什么是编写SQL的最佳方法

  • 得到ID 10,如果我试图找到(A,B,C)
  • 如果我试图找到(A,B),请不要
  • 得到ID 20,如果我试图在(C,D)中找不到

.

Select distinct ID from TableA where Term in (A,B,C) will return both 10 and 20

Select distinct ID from TableA where Term in (A,B) will also return both 10 and 20

Select distinct ID from TableA where Term NOT in (C,D) will also return both 10 and 20
Run Code Online (Sandbox Code Playgroud)

谢谢!

sql

0
推荐指数
1
解决办法
408
查看次数