sql查询转义第一条记录显示降序

时间:2016-11-14 08:01:43

标签: c# sql-server

我想要正确的查询

SELECT '0' AS PropertyDetailId, 'Select PropertyDetail' as PropertyName 
UNION SELECT PropertyDetailId,PropertyDetail.PropertyName 
FROM PropertyDetail join SiteDetail ON 
PropertyDetail.SiteDetailId = SiteDetail.SiteDetailId WHERE 
    PropertyDetail.IsActive = 1 
    AND PropertyDetail.SiteId = 6 
    AND SiteDetail.IsActive = 1 
    AND CustomerId = 0
ORDER BY PropertyName

但我的PropertyDetailId = 0属于下拉列表。 我希望解决这个问题,这是我第一次从Order命令中删除记录

4 个答案:

答案 0 :(得分:1)

只需使用“行号”字段,如下所示:

SELECT 1 AS RN, '0' AS PropertyDetailId, 'Select PropertyDetail' as PropertyName 
UNION 
SELECT 2 AS RN, PropertyDetailId,PropertyDetail.PropertyName 
FROM PropertyDetail 
     JOIN SiteDetail ON PropertyDetail.SiteDetailId = SiteDetail.SiteDetailId 
WHERE 
    PropertyDetail.IsActive = 1 
    AND PropertyDetail.SiteId = 6 
    AND SiteDetail.IsActive = 1 
    AND CustomerId = 0
ORDER BY RN, PropertyName

另一种方法是在下拉列表中显示数据之前在客户端添加记录

答案 1 :(得分:0)

只需排除您不想要的内容。 试试这个

warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: in compilation unit '/Volumes/Data/OneDrive/Singpost/App/Version8c/SingPost/Pods/Realm/Realm/ObjectStore/src/impl/collection_change_builder.cpp' (offset 0x100318):
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x142603 has a DW_AT_specification attribute referring to the die at offset 0x14259e, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x149667 has a DW_AT_specification attribute referring to the die at offset 0x12fb7b, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x149e2d has a DW_AT_specification attribute referring to the die at offset 0x12fbc8, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x14b958 has a DW_AT_specification attribute referring to the die at offset 0x1322de, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x14c766 has a DW_AT_specification attribute referring to the die at offset 0x1323cd, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x14cbdf has a DW_AT_specification attribute referring to the die at offset 0x14b982, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: warning: function at offset 0x14cbdf has no name
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x14cda5 has a DW_AT_specification attribute referring to the die at offset 0x132409, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x1522ed has a DW_AT_specification attribute referring to the die at offset 0x1398bd, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x152bf8 has a DW_AT_specification attribute referring to the die at offset 0x152329, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x152c7c has a DW_AT_specification attribute referring to the die at offset 0x139908, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x154dca has a DW_AT_specification attribute referring to the die at offset 0x13b14a, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x155718 has a DW_AT_specification attribute referring to the die at offset 0x13b726, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x159fb5 has a DW_AT_specification attribute referring to the die at offset 0x143410, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x15a038 has a DW_AT_specification attribute referring to the die at offset 0x14345d, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x15a0bb has a DW_AT_specification attribute referring to the die at offset 0x1453c6, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: the DIE at offset 0x15a397 has a DW_AT_specification attribute referring to the die at offset 0x1434aa, which either was not marked as a declaration, or comes later in the file
warning: dump_syms: /Users/victory1908/Library/Developer/Xcode/DerivedData/SingPost-bsyrfyuoahxzibgwthrzgvnckyff/Build/Products/Debug-iphoneos/SingPost.app.dSYM/Contents/Resources/DWARF/SingPost: in compilation unit '/Volumes/Data/OneDrive/Singpost/App/Version8c/SingPost/Pods/Realm/Realm/ObjectStore/src/collection_notifications.cpp' (offset 0x15a565):

答案 2 :(得分:0)

尝试以下方法。 (按值排序设置为顶部,以便选择' SELECT PROPERTYDETAIL')

    SELECT '0' AS PROPERTYDETAILID
        ,'SELECT PROPERTYDETAIL' AS PROPERTYNAME

    UNION

    SELECT PROPERTYDETAILID
        ,PROPERTYDETAIL.PROPERTYNAME
    FROM PROPERTYDETAIL
    JOIN SITEDETAIL ON PROPERTYDETAIL.SITEDETAILID = SITEDETAIL.SITEDETAILID
    WHERE PROPERTYDETAIL.ISACTIVE = 1
        AND PROPERTYDETAIL.SITEID = 6
        AND SITEDETAIL.ISACTIVE = 1
        AND CUSTOMERID = 0
    ORDER BY CASE PROPERTYNAME WHEN   'SELECT PROPERTYDETAIL' THEN 1 END, PROPERTYNAME

答案 3 :(得分:0)

   with aa as(
    SELECT '0' AS PropertyDetailId, 'Select PropertyDetail' as PropertyName 
    UNION SELECT PropertyDetailId,PropertyDetail.PropertyName 
    FROM PropertyDetail join SiteDetail ON 
    PropertyDetail.SiteDetailId = SiteDetail.SiteDetailId WHERE 
    PropertyDetail.IsActive = 1 
    AND PropertyDetail.SiteId = 6 
    AND SiteDetail.IsActive = 1 
    AND CustomerId = 0
    )
    Select * from aa 
    ORDER BY (case when PropertyDetailId='0' then PropertyDetailId else PropertyName end)