問(wèn)題描述
我有三個(gè)地址行列,aline1、aline2、aline3 表示一條街道地址.從不一致的數(shù)據(jù)上演,它們中的任何一個(gè)或全部都可以空白的.我想將第一個(gè)非空白移動(dòng)到 addrline1,第二個(gè)非空白到 addrline2,如果沒(méi)有三個(gè)非空??行,則清除第 3 行,否則離開它.(第一個(gè)"意味著 aline1 是第一個(gè),除非它是空白的,如果 aline1 為空,則 aline2 是第一個(gè),如果 aline1 和 2,則 aline3 是第一個(gè)都是空白)
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)
這個(gè)臨時(shí)表中的行沒(méi)有鍵,可能有重復(fù)的行.我可以添加一個(gè)密鑰.
The rows in this staging table do not have a key and there could be duplicate rows. I could add a key.
不計(jì)算列舉可能的大case語(yǔ)句空白和非空白的組合并移動(dòng)字段,如何我可以更新表格嗎?(同樣的問(wèn)題出現(xiàn)了更多超過(guò) 3 行,所以這就是為什么我不想使用 case 語(yǔ)句)
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
推薦答案
您可以創(chuàng)建一個(gè)插入和更新觸發(fā)器,檢查字段是否為空,然后移動(dòng)它們.
You could make an insert and update trigger that check if the fields are empty and then move them.
這篇關(guān)于SQL:如何更新多個(gè)字段,以便將空字段內(nèi)容移動(dòng)到邏輯上最后一列 - 丟失空白地址行的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!