問題描述
我有三個地址行列,aline1、aline2、aline3 表示一條街道地址.從不一致的數據上演,它們中的任何一個或全部都可以空白的.我想將第一個非空白移動到 addrline1,第二個非空白到 addrline2,如果沒有三個非空??行,則清除第 3 行,否則離開它.(第一個"意味著 aline1 是第一個,除非它是空白的,如果 aline1 為空,則 aline2 是第一個,如果 aline1 和 2,則 aline3 是第一個都是空白)
I have three address line columns, aline1, aline2, aline3 for a street address. As staged from inconsistent data, any or all of them can be blank. I want to move the first non-blank to addrline1, 2nd non-blank to addrline2, and clear line 3 if there aren't three non blank lines, else leave it. ("First" means aline1 is first unless it's blank, aline2 is first if aline1 is blank, aline3 is first if aline1 and 2 are both blank)
這個臨時表中的行沒有鍵,可能有重復的行.我可以添加一個密鑰.
The rows in this staging table do not have a key and there could be duplicate rows. I could add a key.
不計算列舉可能的大case語句空白和非空白的組合并移動字段,如何我可以更新表格嗎?(同樣的問題出現了更多超過 3 行,所以這就是為什么我不想使用 case 語句)
Not counting a big case statement that enumerates the possible combination of blank and non blank and moves the fields around, how can I update the table? (This same problem comes up with a lot more than 3 lines, so that's why I don't want to use a case statement)
我使用的是 Microsoft SQL Server 2008
I'm using Microsoft SQL Server 2008
推薦答案
您可以創建一個插入和更新觸發器,檢查字段是否為空,然后移動它們.
You could make an insert and update trigger that check if the fields are empty and then move them.
這篇關于SQL:如何更新多個字段,以便將空字段內容移動到邏輯上最后一列 - 丟失空白地址行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!