我需要将这些组合成一个查询,我该怎么做我尝试过Union也许我做错了。有人建议我尝试使用临时表,但不确定我一生中是否曾经使用过临时表。我假设你创建一个表并进行某种插入但是proc的exec怎么样?
DECLARE
@VendorName AS NVARCHAR(100) = 'DOGWOOD TRUCKING',
@Commodity AS NVARCHAR(100) = 'WASTE',
@GLAccount AS NVARCHAR(20),
@CostCenter AS NVARCHAR(20),
@InternalOrderNum AS NVARCHAR(20),
@BeginDate AS DATE = '3/1/2016',
@EndDate AS DATE = '3/31/2016'
DECLARE
@InvoiceDate AS NVARCHAR(10) = (SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY])
SELECT TOP 1
Vendor_Name,
Vendor_Address,
Vendor_City,
Vendor_State,
Vendor_Zip_Code,
ISNULL(Vendor_Email, ' ') AS 'Vendor_Email',
ISNULL(Vendor_Phone_1, ' ') AS 'Vendor_Phone',
Vendor_SAP_Num,
@InvoiceDate AS 'Invoice_Date',
@BeginDate AS 'Invoice_Start_Date',
@EndDate AS 'Invoice_End_Date'
FROM
dbo.List_Vendors
WHERE
Vendor_Name = @VendorName
EXEC [dbo].[VB_Truck_Report_Sell_Invoice] @VendorName, @Commodity, @BeginDate, @EndDate
答案 0 :(得分:0)
我认为您不需要UNION查询。我想你需要把它放在一起。也许我错了,但希望它有所帮助:
DECLARE
@VendorName AS NVARCHAR(100) = 'DOGWOOD TRUCKING',
@Commodity AS NVARCHAR(100) = 'WASTE',
@GLAccount AS NVARCHAR(20),
@CostCenter AS NVARCHAR(20),
@InternalOrderNum AS NVARCHAR(20),
@BeginDate AS DATE = '3/1/2016',
@EndDate AS DATE = '3/31/2016'
DECLARE
@InvoiceDate AS NVARCHAR(10) = (SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY])
SELECT TOP 1
Vendor_Name,
Vendor_Address,
Vendor_City,
Vendor_State,
Vendor_Zip_Code,
ISNULL(Vendor_Email, ' ') AS 'Vendor_Email',
ISNULL(Vendor_Phone_1, ' ') AS 'Vendor_Phone',
Vendor_SAP_Num,
@InvoiceDate AS 'Invoice_Date',
@BeginDate AS 'Invoice_Start_Date',
@EndDate AS 'Invoice_End_Date,
@Commodity,
@GLAccount,
@CostCenter,
@InternalOrderNum,
@BeginDate,
@EndDate,
@InvoiceDate
FROM
dbo.List_Vendors
WHERE
Vendor_Name = @VendorName
然后你会把它们放在一起。
希望它有所帮助,告诉我,我有什么不对的帮助。