我有来自多个表的多个记录。我需要将这些记录插入到我稍后传递的临时表中。问题是当我将行插入临时表时,它插入的数据行意味着每列行 id 计数器都会增加。我需要明智地插入数据列。表示每一列(我从差异表中获取记录)rowId 计数器从 1 开始。如果我在第一列中插入数据,我的行 id 计数器为 1-5(如果有 5 行)。如果我触发了从第 6 行插入到临时表中的第二条语句(对于第 2 列)数据。剩余的(1-5)是空值。有什么解决办法。请帮我。任何线索都是可观的。提前致谢!下面是我的程序...
alter PROCEDURE procGetPreviousOrderDetails --(@userid nvarchar(100))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @recentViewedProduct nvarchar(max)
declare @AccountCreatedDate nvarchar(100)
declare @recentViewedCategories nvarchar(max)
declare @recentOrderProductList nvarchar(max)
declare @dateOflastPurchase nvarchar(max)
declare @shippingMethodList nvarchar(max)
declare @paymentMethodList nvarchar(max)
declare @totalOrderAmount nvarchar(100)
declare @zipCode nvarchar(100)
declare @tblOrderDetails table
(
RowId int identity(1,1),
recentViewedProduct nvarchar(max),
trailType int,
AccountCreatedDate nvarchar(100),
recentViewedCategories nvarchar(max),
recentOrderProductList nvarchar(max),
dateOflastPurchase nvarchar(max),
shippingMethodList nvarchar(max),
paymentMethodList nvarchar(max),
totalOrderAmount nvarchar(100),
zipCode nvarchar(100)
)
if (select count(@@rowcount) from @tblOrderDetails) > 0
begin
truncate table tblOrderDetails
end
insert into @tblOrderDetails(recentViewedProduct) select RV.item_name, RV.trail_type from tblCMRecentlyViewed RV where RV.trail_type in (1, 2) and RV.user_id = '807CF717-9413-4CC3-8982-FF63A6B31906' order by RV.date_added desc
insert into @tblOrderDetails(AccountCreatedDate) select d_date_registered from UserObject where g_user_id = '807CF717-9413-4CC3-8982-FF63A6B31906'
select distinct product_id from OrderFormLineItems where ordergroup_id = (select TOP 1 ordergroup_id from Ordergroup where user_id='807CF717-9413-4CC3-8982-FF63A6B31906'
order by order_create_date desc)
select TOP 1 order_create_date from Ordergroup where user_id='807CF717-9413-4CC3-8982-FF63A6B31906' order by order_create_date desc
select distinct display_name from ShipMethods where carrier_ship_method_id = (select distinct ship_method_id from Ordergroup where user_id='328239F8-A983-442C-A9E6-ADC203D5F52B')
select distinct saved_payment_type from OrderFormHeader where ordergroup_id in (select distinct ordergroup_id from Ordergroup where user_id='328239F8-A983-442C-A9E6-ADC203D5F52B')
select SUM(saved_cy_total_total) from Ordergroup where user_id='807CF717-9413-4CC3-8982-FF63A6B31906'
select distinct u_postal_code from Addresses where g_id = '807CF717-9413-4CC3-8982-FF63A6B31906'
谢谢!