SQL查询需要帮助................ [英] Needed Help For SQL Query ................

查看:56
本文介绍了SQL查询需要帮助................的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server表结构如下
-------------------
1. CompanyID int,分支varchar(100)

1.上表数据为
------------------------------
1''1,2,3''
2''2,3''
3''1,3''

2. BranchID int,BranchName varchar(100)

2.上表数据为
------------------------------
1``悉尼''
2``纽约''
3``洛杉矶''


问:第一个表的必需结果,因为不使用标量函数
-------------------------------------------------- -------------
1''悉尼,纽约,洛杉矶''
2``纽约,洛杉矶''
3"洛杉矶,悉尼"

SQL Server Table Structure as follows
-------------------
1. CompanyID int,Branches varchar(100)

1. Data for above table is
------------------------------
1 ''1,2,3''
2 ''2,3''
3 ''1,3''

2. BranchID int,BranchName varchar(100)

2. Data for above table is
------------------------------
1 ''Sydney''
2 ''New York''
3 ''Los Angeles''


Q. Required Result from 1st table as without using scalar function
---------------------------------------------------------------
1 ''Sydney,New York,Los Angeles''
2 ''New York,Los Angeles''
3 ''Sydney,Los Angeles''

推荐答案

看看这是否能解决您的问题,

http://mangalpardeshi.blogspot.com/2009/03/how- to-split-comma-delimited-string.html [ ^ ]

(您可能需要对其进行定制以满足您的自定义要求)
See if this solves your problem,

http://mangalpardeshi.blogspot.com/2009/03/how-to-split-comma-delimited-string.html[^]

(You might need to tailor it to meet your custom requirement)


您的问题与此问题类似:

如何为选择两个表数据创建过程 [ ^ ]

请更改其解决方案,使其适合您的需求.
Your question is similar to this question :

how to create procedue for select two table data[^]

Please change its solution so it fits your needs.


伪代码

1.将变量声明为cursur
2.做
3.获取Braches的值(到@val).
4.获取字符串值(以逗号分隔),并使用拆分它(令牌).
5. SET @strVar = BrachName来自TBLBraches2 WHERE BrachID = @val
6. PRINT @strVar +''''
7.循环(当前记录数)
8.结束
Pseudocode

1. Declare a variable as cursur
2. Do
3. Fetch the value of Braches (to @val).
4. Get the string value(comma delimited) and use split it(token).
5. SET @strVar = BrachName FROM TBLBraches2 WHERE BrachID = @val
6. PRINT @strVar + '' ''
7. Loop(recordcount of cursur)
8.End


这篇关于SQL查询需要帮助................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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