久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

水平顯示查詢結果

Displaying Query Results Horizontally(水平顯示查詢結果)
本文介紹了水平顯示查詢結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道是否可以獲取查詢結果并將它們作為 CSV 字符串而不是作為一列單元格返回.

I am wondering if it is possible to take the results of a query and return them as a CSV string instead of as a column of cells.

基本上,我們有一個名為Customers 的表,還有一個名為CustomerTypeLines 的表,每個Customer 可以有多個CustomerTypeLines.當我針對它運行查詢時,當我想檢查多種類型時會遇到問題,例如:

Basically, we have a table called Customers, and we have a table called CustomerTypeLines, and each Customer can have multiple CustomerTypeLines. When I run a query against it, I run into problems when I want to check multiple types, for instance:

    Select * 
      from Customers a 
Inner Join CustomerTypeLines b on a.CustomerID = b.CustomerID 
     where b.CustomerTypeID = 14 and b.CustomerTypeID = 66

...不返回任何內容,因為客戶不能同時擁有兩者,很明顯.

...returns nothing because a customer can't have both on the same line, obviously.

為了使它工作,我必須向客戶添加一個名為 CustomerTypes 的字段,它看起來像 ,14,66,67, 這樣我就可以做一個 Where a.CustomerTypes like'%,14,%' 和 a.CustomerTypes 像 '%,66,%' 返回 85 行.

In order to make it work, I had to add a field to Customers called CustomerTypes that looks like ,14,66,67, so I can do a Where a.CustomerTypes like '%,14,%' and a.CustomerTypes like '%,66,%' which returns 85 rows.

當然這很痛苦,因為每次更改 CustomerTypeLines 表時,我都必須讓我的程序為該客戶重建此字段.

Of course this is a pain because I have to make my program rebuild this field for that Customer each time the CustomerTypeLines table is changed.

如果我可以在我的 where 中做一個子查詢來為我做這項工作,那就太好了,而不是像這樣返回結果:

It would be nice if I could do a sub query in my where that would do the work for me, so instead of returning the results like:

14
66
67

它會像 ,14,66,67,

這可能嗎?

推薦答案

您將在以逗號分隔的列表上執(zhí)行 LIKE 查詢時遇到各種問題.我知道,我去過那里.

You're going to run into all kinds of problems doing a LIKE query on a comma-delimited list. I know, I've been there.

例如,如果您搜索 '%,14,%',如果 14 是列表中的第一項或最后一項會怎樣?(我意識到您指定了額外的前導和尾隨逗號,但 COALESCE 方法不提供這些.)

For example, if you search for '%,14,%', what happens if 14 is the first or last item in the list? (I realize you specify extra leading and trailing commas, but the COALESCE method doesn't supply those.)

這個怎么樣:

Select * from Customers a 
Inner Join CustomerTypeLines b 
on a.CustomerID = b.CustomerID 
WHERE a.CustomerID in 
    (SELECT customerID from CustomerTypeLines
     WHERE CustomerTypeID = 14)
AND a.CustomerID in
    (SELECT customerID from CustomerTypeLines
     WHERE CustomerTypeID in 66)

編輯以解決過快閱讀問題的問題!

這篇關于水平顯示查詢結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 中文字幕精品一区久久久久 | 国产精品亚洲精品日韩已方 | 亚卅毛片 | 亚洲导航深夜福利涩涩屋 | 亚洲日韩第一页 | 国产成人精品久久久 | 欧美成人激情 | 麻豆一区二区三区 | 九九在线视频 | 99视频免费看 | 97国产在线视频 | 国产精品不卡 | 另类视频区| 国产精品69毛片高清亚洲 | 91精品国产高清一区二区三区 | 成人久久网 | 欧美色综合一区二区三区 | 北条麻妃视频在线观看 | 久久精品免费 | 国产专区视频 | 精品欧美一区二区三区久久久小说 | 成人在线观看中文字幕 | 亚洲在线一区 | 久久专区| 精品福利在线 | 欧美一级久久久猛烈a大片 日韩av免费在线观看 | av色噜噜| 操久久| 久久精品视频网站 | 日韩成人免费视频 | av一二三区 | 亚洲成人第一页 | 欧美日韩国产在线 | 美女视频h | 欧美综合在线视频 | 国产精品视频免费播放 | 亚洲第一黄色网 | 色欧美片视频在线观看 | 亚洲一区视频在线 | 日韩av免费在线观看 | 欧美一级二级三级 |