在datalist中重复相同的数据 [英] Repeat same data in datalist

查看:70
本文介绍了在datalist中重复相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在桌子上的12张贴纸的A4 Lebel表上打印相同的地址名称。

我使用的是数据列表,无法在12级填充所有,只显示一次。需要重复12次。

SELECT *来自客户,其中CustID ='101'

建议更好的解决方案。



我的尝试:



I want to print same name with address on a A4 Lebel sheet of 12 Sticker from table.
I am using datalist,not able to fill all on 12 level, it shows only one time.It require to repeat 12 times.
SELECT * from Customer where CustID='101'
Suggest better solution.

What I have tried:

SELECT * from Customer where CustID='101'

推荐答案

我根本不推荐它 - 这绝对是你应该用你的演示语言而不是SQL的东西。 />


然而,解决方案1是错误的:它是非常可能的,如果相当讨厌。

首先创建一个名为Count12的表 - 它需要一个名为Counter的INT列。

用12个值填充:

I don't recommend it at all - this is definitely something that you should be doing in your presentation language, not in SQL.

However, Solution 1 is wrong: it;'s very possible, if rather nasty.
Start by creating a table called Count12 - it needs a single INT column called Counter.
Fill it with 12 values:
Counter
1
2
3
4
5
6
7
8
9
10
11
12

然后这是一个简单的JOIN来获得相同的结果12次:

Then it's a simple JOIN to get the same info 12 times:

SELECT a.Name, a.Address FROM Count12 b
JOIN MyTable a ON 1=1

如果使Count表包含1000行,则可以使用WHERE限制副本数:

If you make the Count table contain say 1000 rows, you can restrict the number of copies using WHERE:

SELECT a.Name, a.Email FROM Count12 b
JOIN MyTable a ON 1=1
WHERE b.Counter <= 5

例如,每行会给你5份副本。



你现在还能过得更好用你的演示语言来做。

Will give you 5 copies of each row for example.

You're still better off doing it in your presentation language though.


你需要对一个数字列表使用CROSS JOIN - 参见CP文章交叉连接简介 - 创建行组合 [ ^ ]



例如:为自己生成一个系列...
You need to use a CROSS JOIN against a list of numbers - See CP article Cross Join Introduction – Create Row Combinations[^]

For example: Generating a series for yourself ...
declare @Customer table (CustID int, CustName nvarchar(100))
insert into @Customer (CustID, CustName) values (101, 'My test data')


;with series as
(
	select 1 as datum
	UNION ALL
	select datum + 1
	from series where datum + 1 < 13
)
SELECT * from @Customer 
cross join series
where CustID=101

或者您可以使用系统表生成这样的序列

OR you can use the system tables to generate a sequence like this

SELECT * from @Customer 
CROSS JOIN (SELECT TOP (12) ROW_NUMBER() OVER (ORDER BY [object_id]) as datum FROM sys.all_objects) AS series
WHERE CustID=101


据我所知,这是不可能的,因为sql或mysql不能多次选择相同的数据,因为他想要一些独特的b / w它们可以是id,任何文本或任何东西。例如我有五列id,名称,国家,城市,状态和值是

1 John PK KHI 1

2史密斯PK KHI 1

3 John PK KHI 1

在这个例子中你可以得到两次john但是有一个这是唯一的b / w它们是id。但即使你在列选择中过滤它也不能选择两次id为1的john。

如果你在想 UNION 它也不可能。在PHP代码或js代码或.net代码中只有一件事可以在sql或mysql之外执行此操作。
In my knowledge it's not possible because sql or mysql can not select same data multiple time because he want sometime unique b/w them it can be id, any text, or anything. For example i have five columns id, name, country, city, status and values are
1 John PK KHI 1
2 Smith PK KHI 1
3 John PK KHI 1
in this example you can get john twice but there is one this is unique b/w them is id. But it can't select john twice having id 1 even if you will filter it in the column selection.
If you were thinking about UNION it's also not possbile. Only one thing is possible do this outside sql or mysql like in php code or js code or .net code.


这篇关于在datalist中重复相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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