简体   繁体   English

用于格式化GridView中DataSource的表数据的SQL查询

[英]SQL query to format table data for DataSource in GridView

I am looking for a SQL Server query that could transfer source SQL table data: 我正在寻找可以传输源SQL表数据的SQL Server查询:

TextID | Text  | LanguageID
-------|-------|-------------------------------------
app.aa | Hi    | 6a13ea09-46ea-4c93-9b6a-e26bdc6ff4d8
app.cc | Hund  | 0c894bb7-4937-4903-906a-d1b1dd64935c
app.aa | Hallo | 0c894bb7-4937-4903-906a-d1b1dd64935c
app.cc | Dog   | 6a13ea09-46ea-4c93-9b6a-e26bdc6ff4d8
app.bb | Star  | 6a13ea09-46ea-4c93-9b6a-e26bdc6ff4d8
... 

into table like this one: 像这样的表:

TextID | Original | Translated
-------|----------|-----------
app.aa | Hi       | Hallo
app.bb | Star     | -
app.cc | Dog      | Hund
...

so that I can use it as a DataSource for GridView in ASP .NET. 这样我就可以在ASP .NET中将它用作GridView的DataSource。 Thank you in advance for your help. 预先感谢您的帮助。

Whenever you need to combine data from two different rows into one, you need to join . 每当您需要将来自两个不同行的数据合并为一个时,您需要加入 For example: 例如:

select src.TextID "TextID", src.Text "Original", tr.Text "Translated"
from source_table src
left join source_table tr
on src.TextID = tr.TextID
and src.LangID = 'xxx'  -- xxx is the source language id
and tr.LangID = 'yyy' -- yyy is the target language id

The left join ensures that untranslated words are included with a null translated value. 左连接确保未翻译的单词包含空翻译值。 To make a table for your DataSource, you'll need to wrap create table (or maybe create view ) around the select : 要为DataSource创建一个表,您需要在select周围包装create table (或者创建视图 ):

create table translations as
    select ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM