如何从SQL Server的值列表中选择 [英] How can I select from list of values in SQL Server

查看:114
本文介绍了如何从SQL Server的值列表中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法解决的非常简单的问题.我需要做这样的事情:

I have very simple problem that I can't solve. I need to do something like this:

select distinct * from (1, 1, 1, 2, 5, 1, 6).

任何人都可以帮忙吗?

修改

数据来自一个客户的文本文件.它是完全未格式化的(它是一行很长的一行文本),但是在Excel中也可以这样做.但这对我来说不切实际,因为我将需要在sql查询中使用这些值.每次我需要运行查询时,这样做都不方便.

The data comes as a text file from one of our clients. It's totally unformatted (it's a single, very long line of text), but it may be possible to do so in Excel. But it's not practical for me, because I will need to use these values in my sql query. It's not convenient to do so every time I need to run a query.

推荐答案

获取长逗号分隔文本列表的 distinct值的最简单方法是使用查找替换为 UNION 以获得不同的值.

Simplest way to get the distinct values of a long list of comma delimited text would be to use a find an replace with UNION to get the distinct values.

SELECT 1
UNION SELECT 1
UNION SELECT 1
UNION SELECT 2
UNION SELECT 5
UNION SELECT 1
UNION SELECT 6

适用于您用逗号分隔的长行文本

Applied to your long line of comma delimited text

  • 查找并用UNION SELECT替换每个逗号
  • 在语句前面添加SELECT
  • Find and replace every comma with UNION SELECT
  • Add a SELECT in front of the statement

您现在应该有一个有效的查询

You now should have a working query

这篇关于如何从SQL Server的值列表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆