我在SQL Server中,如下3代表的表:创建SQL Server中几个条件
EnquiryTable
:
EndID FyYear SNo ServiceID MaterialID
55 2015 1 1 1
55 2015 2 5 3
ServiceTable
:
ServiceID ServiceName
1 ServiceA
2 ServiceB
3 ServiceC
4 ServiceD
5 ServiceE
Material
表:
MaterialID MaterialName
1 MaterialA
2 MaterialB
3 MaterialC
我需要从stored procedure
返回如下表格,以便该表格最终有助于绑定gridview
。
结果表:
SNo ServiceName MaterialName
1 ServiceA MaterialA
2 ServiceE MaterialC
基本上需要将从EnquiryTable
与ServiceTable
和MaterialTable
比较ServiceIds, MaterialIds
,并用ServiceNames
和MaterialNames
返回回所得表的过程。
我试过类似如下:
declare @serviceID int
declare @matID int
select sno, [email protected],[email protected] from dbo.enquirytable
但@serviceID, @matID
变量返回null
。
请专家帮忙。
我正在使用SQL Server 2008 R2。
问候
您可能会发现回答这个有用https://msdn.microsoft.com/en-us/library/ms345415.aspx – 2015-02-09 18:01:42