开发者社区> 问答> 正文

为什么无法创建#Articole表

为什么无法创建#Articole表

展开
收起
贺贺_ 2019-12-02 21:14:37 504 0
1 条回答
写回答
取消 提交回答
  • 由于我不知道实际查询中表的架构,下面是预先创建表的诀窍。

    select top 0 im.ItemName, im.ItemCode, d.ItemId as PromoId, im.Enabled, im.ItemId, dfv.DiscountFilterValueId
    into #Articol
    from Discount d (nolock) 
    join DiscountFilter df (nolock) on df.DiscountId = d.ItemId
    Join DiscountFilterValue dfv (nolock) on dfv.DiscountFilterId = df.DiscountFilterId
    join Item i (nolock) on d.ItemId = i.ItemId
    Join Item im (nolock) on im.ItemId = dfv.TextValue
    where df.EntityId = 184
    
    @Sql NVarchar(max)
    set @Articol = 99190
    set @Sql=N'
    insert into #Articol
    select im.ItemName, im.ItemCode, d.ItemId as PromoId, im.Enabled, im.ItemId, dfv.DiscountFilterValueId
    from Discount d (nolock) 
    join DiscountFilter df (nolock) on df.DiscountId = d.ItemId
    Join DiscountFilterValue dfv (nolock) on dfv.DiscountFilterId = df.DiscountFilterId
    join Item i (nolock) on d.ItemId = i.ItemId
    Join Item im (nolock) on im.ItemId = dfv.TextValue
    where df.EntityId = 184'
    
    IF @Articol <> -1 set @Sql = @Sql + ' and im.ItemId = @Articol'
    If @Articol = -1 set @Sql = @Sql
    exec sp_executesql @Sql, N'@Articol int', @Articol
    
    select * from #Articole
    
    2019-12-02 21:16:19
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
RowKey与索引设计:技巧与案例分析 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载