【发布时间】:2016-10-24 06:37:56
【问题描述】:
我正在尝试使用子查询从表中获取数据,但出现此错误:
基表:[tblPriscription]
[Priscriptionid] [bigint] IDENTITY(1,1) NOT NULL,
[patientId] [bigint] NULL,
[doctorId] [bigint] NULL,
[BillNo] AS ([Priscriptionid]+(100)),
[BillDate] [datetime] NULL,
[BillType] [nvarchar](50) NULL,
[PaymentBy] [nvarchar](50) NULL,
[DocumentType] [nvarchar](50) NULL,
[DocumentName] [nvarchar](50) NULL,
[bitIsActive] [bit] NULL,
[dateCreated] [date] NULL,
[bitIsDelete] [bit] NULL,
[bitisSave] [bit] NULL,
[TotalAmount] [decimal](18, 2) NULL,
我要从中获取数据的表:
dbo.tblPriscriptionDetail
[PriscriptionDtlid] [bigint] IDENTITY(1,1) NOT NULL,
[Priscriptionid] [bigint] NULL,
[drugId] [bigint] NULL,
[Rxno] [bigint] NULL,
[sigId] [bigint] NULL,
[Selling] [decimal](18, 2) NULL,
[Qty] [int] NULL,
[RefillQty] [int] NULL,
[RefillNo] [int] NULL,
[Days] [int] NULL,
[Amount] [decimal](18, 2) NULL,
[bitIsActive] [bit] NULL,
[dateCreated] [datetime] NULL,
[bitIsDelete] [bit] NULL,
[PurchaseDtlid] [bigint] NULL,
[bitIsSave] [bit] NULL,
[BillType] [nvarchar](50) NULL,
[PaymentBy] [nvarchar](50) NULL,
[patientId] [bigint] NULL,
[id] [bigint] NULL,
Qyery:
SELECT *,
(SELECT insuranceName
FROM tblinsurance
WHERE insuranceid = (SELECT insuranceid
FROM tblpatient
WHERE PatientId = tblPriscription.PatientId)) AS insuranceName,
(SELECT drfirstname + ' ' + drlastname
FROM tbldoctor
WHERE doctorid = tblPriscription.doctorid) AS doctorname,
(SELECT patFirstName + ' ' + patLastName
FROM tblPatient
WHERE patientid = tblPriscription.patientid) AS patname,
(SELECT policyno
FROM tblPatient
WHERE patientid = tblPriscription.patientid) AS policyno,
(SELECT insuranceplanname
FROM tblInsurancePlan
WHERE insuranceplanid = (SELECT insuranceplanid
FROM tblpatient
WHERE PatientId = tblPriscription.PatientId)) AS insurancePlanName,
(SELECT drugname
FROM tblDrugMaster
WHERE drugid = (SELECT drugid
FROM tblPriscriptionDetail
WHERE priscriptionid = tblPriscriptionDetail.priscriptionid)) AS drugname,
(SELECT qty
FROM tblPriscriptionDetail
WHERE priscriptionid = tblPriscriptionDetail.priscriptionid) AS qty,
(SELECT Selling
FROM tblPriscriptionDetail
WHERE priscriptionid = tblPriscriptionDetail.priscriptionid) AS selling
FROM tblPriscription
我正在尝试从 tblPriscriptionDetail 药物名称、数量和销售建议中获取数据,该怎么做
【问题讨论】:
标签: c# asp.net sql-server database sql-server-2008