0

Why am I getting an incorrect syntax near 'dbo'. error?

SELECT inv_num
INTO #InvoiceList
FROM (
SELECT inv_num = 
    dbo.ExpandKy(10, @Inv1) UNION ALL
    dbo.ExpandKy(10, @Inv2) UNION ALL
    dbo.ExpandKy(10, @Inv3) UNION ALL
    dbo.ExpandKy(10, @Inv4) UNION ALL
    dbo.ExpandKy(10, @Inv5) UNION ALL
    dbo.ExpandKy(10, @Inv6) UNION ALL
    dbo.ExpandKy(10, @Inv7) UNION ALL
    dbo.ExpandKy(10, @Inv8) UNION ALL
    dbo.ExpandKy(10, @Inv9) UNION ALL
    dbo.ExpandKy(10, @Inv10) UNION ALL
    dbo.ExpandKy(10, @Inv11) UNION ALL
    dbo.ExpandKy(10, @Inv12) UNION ALL
    dbo.ExpandKy(10, @Inv13) UNION ALL
    dbo.ExpandKy(10, @Inv14) UNION ALL
    dbo.ExpandKy(10, @Inv15) UNION ALL
    dbo.ExpandKy(10, @Inv16) UNION ALL
    dbo.ExpandKy(10, @Inv17) UNION ALL
    dbo.ExpandKy(10, @Inv18) UNION ALL
    dbo.ExpandKy(10, @Inv19) UNION ALL
    dbo.ExpandKy(10, @Inv20)
) d
WHERE inv_num IS NOT NULL
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

Your union query is not valid. It should resemble this

select dbo.Exandkey(10, @Inv1) invnum
union all
select dbo.Exandkey(10, @Inv2) invnum
etc
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43