SQL语句(NULL值的问题--在线等待--50分)
有(Sample,Experimenter,Company,Person)4个表
SAMPLE表中有5个字段分别连接其他3个表(Experimenter 1个,Company 2个,Person 2个)
以下存储过程运行的时候。
如果5个连接字段中没有1个为NULL,则返回正常(1条记录)。
如果5个其中有1个为NULL,则没有数据返回。
请高手指点,急。。。在线等待
USE [QIIMS]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N '[dbo].[spSelectSample] ') AND type in (N 'P ', N 'PC '))
DROP PROCEDURE [dbo].[spSelectSample]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spSelectSample]
@SampleID nvarchar(50)=null
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ExperimenterID int
DECLARE @CommissionCompanyID int
DECLARE @ProduceCompanyID int
DECLARE @SamplePerson int
DECLARE @LinkPerson int
SELECT @ExperimenterID=[ExperimenterID]
,@CommissionCompanyID=[CommissionCompanyID]
,@ProduceCompanyID=[ProduceCompanyID]
,@SamplePerson=[SamplePerson]
,@LinkPerson=[LinkPerson]
FROM [QIIMS].[dbo].[Sample]
WHERE SampleID=@SampleID;
SELECT *
FROM
(
SELECT [SampleID]
,[Name]
,[BatchNumber]
,[Amount]
,[TypeLevel]
,[InspectionType]
,[NationalStandard]
,[LimitTime]
,[RegistrationTime]
,[InvoiceNumber]
,[Heading]
,[Result]
,[State]
,[Remark]
,[Time]
FROM [QIIMS].[dbo].[Sample]
WHERE SampleID=@SampleID
) AS A
,
(
SELECT [ExperimenterID]
,[Name]
,[Address]
,[Telephone]
,[Email]
FROM [QIIMS].[dbo].[Experimenter]
WHERE ExperimenterID=@ExperimenterID
) AS B
,
(
SELECT isnull([CompanyID], ' ')as bbb
--,[Name]
--,[Address]
--,[Postalcode]
--,[Telephone]
FROM [QIIMS].[dbo].[Company]
WHERE CompanyID=@CommissionCompanyID
) AS C
,
(
SELECT [CompanyID]