sql server 2008中的sp问题 [英] sp problem in sql server 2008
问题描述
嗨朋友们,
我有两张桌子,
DepartmentMaster字段是
Hi friends,
I have Two tables,
DepartmentMaster fields are
[DeptId] [int] IDENTITY(1,1) NOT NULL,
[DeptName] [varchar](250) NULL,
[Description] [varchar](max) NULL,
和
And
tbl_RFIDReader_M fields are
[ReaderId] [int] IDENTITY(1,1) NOT NULL,
[ReaderName] [varchar](250) NULL,
[OrganizationName] [varchar](250) NULL,
[DepartmentID] [varchar](max) NULL,
[Isdeleted] [varchar](100) NULL,</pre>
和数据
DepartmentMaster
DeptId | DeptName |描述
1 | Dept1 |部门1
2 |部门2 |部门2
3 | Dept3 |部门3
And Data are
DepartmentMaster
DeptId|DeptName|Description
1 | Dept1 | Department1
2 | Dept2 |Department2
3 | Dept3 | Department3
tbl_RFIDReader_M
ReaderId | ReaderName | Org..Name | DepartmentId | IsDeleted
1 | Reader1 | Org1 | 1,2 | 0
2 | Reader2 | Org2 | 2,3 | 0
现在我必须在gridview中显示
ReaderId|ReaderName|Org..Name|DepartmentId|IsDeleted
1 | Reader1 | Org1 | 1,2 | 0
2 | Reader2 | Org2 | 2,3 | 0
now I have to display
tbl_RFIDReader_M
但是我想要名字而不是id
示例
in gridview but i want Names Instead of id
example in
tbl_RFIDReader_M
departmentId在显示中是'1,2'我想要'Dept1,Dept2 'by sp。
所以请帮我制作这个商店的程序。
departmentId is '1,2 ' in Display i want 'Dept1,Dept2' by sp.
so please help me to make store procedure of this.
推荐答案
没有。
为什么不呢?因为这是一个非常非常讨厌的工作,因为你的数据库设计是错误的,并且需要改变 - 如果我帮助你在这里躲避它,那么明天或下周(以及接下来的几天和/或几周)你会回来更多所有问题都是由这一个错误引起的。
不要将数值存储为字符串。特别是,不要将值列表存储为字符串中的逗号分隔值。更具体地说,不要在(1)不支持CSV数据的环境中这样做; (2)具有非常基本的字符串处理。
不要将DepartmentID作为CSV字符串存储,而是创建一个将DeptID与ReaderID相关联的新表 - 这样您就可以存储每个协会作为一个单独的行:
No.
Why not? Because it's a really, really nasty job because your database design is wrong, and needs changing - and if I help you bodge round it here, you will be back tomorrow, or next week, (and succeeding days and / or weeks) with more problems all caused by this one error.
Don't store numeric values as strings. And particularly, don't store lists of values as comma separated values in a string. And even more particularly, don't do this in an environment which (1) doesn't support CSV data; and (2) has pretty basic string handling.
Instead of storing your DepartmentIDs as a CSV string, create a new table which associates DeptID with ReaderID - so you can store each association as a separate row:
ReaderID DeptID
1 1
1 2
2 2
2 3
...
这样,您可以使用JOIN轻松地将DeptId转换为名称,并简单地使用常规机制。它会让你的生活变得更加轻松,以后也会更容易。
That way, you can use a JOIN to convert DeptId to the name easily, and simply using the normal mechanisms. And it will make your life a lot, lot easier later on as well.
这篇关于sql server 2008中的sp问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!