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

水平顯示查詢結(jié)果

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

問題描述

我想知道是否可以獲取查詢結(jié)果并將它們作為 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.當(dāng)我針對它運(yùn)行查詢時,當(dāng)我想檢查多種類型時會遇到問題,例如:

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

...不返回任何內(nèi)容,因?yàn)榭蛻舨荒芡瑫r擁有兩者,很明顯.

...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.

當(dāng)然這很痛苦,因?yàn)槊看胃?CustomerTypeLines 表時,我都必須讓我的程序?yàn)樵摽蛻糁亟ù俗侄?

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 中做一個子查詢來為我做這項(xiàng)工作,那就太好了,而不是像這樣返回結(jié)果:

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 是列表中的第一項(xiàng)或最后一項(xiàng)會怎樣?(我意識到您指定了額外的前導(dǎo)和尾隨逗號,但 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)

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

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

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

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 精品久久久久久久久亚洲 | 在线播放亚洲 | 午夜精品久久久久久久星辰影院 | 国产女人与拘做视频免费 | 欧美日韩久久精品 | 嫩草黄色影院 | 手机在线观看 | 国产精品久久久久久婷婷天堂 | 在线日韩不卡 | 99国产精品久久久久老师 | 老头搡老女人毛片视频在线看 | 成人高清网站 | 精品亚洲一区二区三区四区五区 | 欧美激情精品久久久久久变态 | 在线亚洲欧美 | 日韩毛片在线免费观看 | 精品一区二区三区在线视频 | www.日韩| 国产成人自拍一区 | 欧美日韩国产一区二区三区不卡 | 午夜精品一区二区三区在线视 | 久久综合伊人一区二区三 | 最新中文字幕第一页视频 | 国产69久久精品成人看动漫 | 亚洲毛片| 久久久久久国产免费视网址 | 午夜专区 | 北条麻妃一区二区三区在线观看 | 欧美成视频在线观看 | 久久久久国产 | 国产日韩欧美综合 | 福利视频亚洲 | 伊人色综合久久天天五月婷 | 在线观看亚 | 日韩国产一区二区三区 | 亚洲在线一区二区 | 视频一区二区在线观看 | 91久久综合亚洲鲁鲁五月天 | 中文字幕亚洲区一区二 | 91精品国产乱码久久久 | 婷婷中文字幕 |