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

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

Displaying Query Results Horizontally(水平顯示查詢結(jié)果)
本文介紹了水平顯示查詢結(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.

基本上,我們有一個(gè)名為Customers 的表,還有一個(gè)名為CustomerTypeLines 的表,每個(gè)Customer 可以有多個(gè)CustomerTypeLines.當(dāng)我針對它運(yùn)行查詢時(shí),當(dāng)我想檢查多種類型時(shí)會(huì)遇到問題,例如:

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(shí)擁有兩者,很明顯.

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

為了使它工作,我必須向客戶添加一個(gè)名為 CustomerTypes 的字段,它看起來像 ,14,66,67, 這樣我就可以做一個(gè) 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 表時(shí),我都必須讓我的程序?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 中做一個(gè)子查詢來為我做這項(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

它會(huì)像 ,14,66,67,

這可能嗎?

推薦答案

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

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)會(huì)怎樣?(我意識到您指定了額外的前導(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.)

這個(gè)怎么樣:

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)
主站蜘蛛池模板: 伊人免费在线 | 亚洲毛片在线观看 | www.国产精 | 色综合久| 免费视频一区二区 | 亚洲国产精品99久久久久久久久 | 久久久久九九九女人毛片 | 国产做爰| 成人av在线播放 | 欧美日韩综合一区 | 国产亚洲一区在线 | 激情小视频 | 久久久久免费精品国产小说色大师 | 欧美在线观看一区 | 婷婷久久久久 | 91网站在线看 | 91精品免费视频 | 在线观看涩涩视频 | 狠狠干在线 | 美美女高清毛片视频免费观看 | 国产精品久久久久久久久久妇女 | 日韩高清www| 亚洲日韩中文字幕一区 | 日本三级全黄三级三级三级口周 | 在线免费观看黄a | 日韩欧美在线播放 | 在线观看视频一区 | 9999久久| 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 成人h片在线观看 | 在线观看免费观看在线91 | 亚洲精品www | 在线一区视频 | 日韩在线视频一区 | 久久精品国产一区 | 91久久综合 | 国产精品毛片久久久久久 | 成人夜晚看av | 久久国产精品久久 | 一区二区三区精品在线 | 日韩成人在线观看 |