SORU
25 ŞUBAT 2009, ÇARŞAMBA


Nasıl tek bir deyim içinde birden çok ortak tablo ifadeleri alabilir miyim?

Karmaşık bir deyim basitleştirme sürecinde yaşıyorum, bu yüzden ortak tablo ifadeleri kullanma düşündüm.

Tek bir cte ilan gayet iyi çalışıyor.

WITH cte1 AS (
    SELECT * from cdr.Location
    )

select * from cte1 

Ve aynı SEÇMEK birden fazla cte ilan kullanmak mümkün mü?

yani bu bir sql hatası veriyor

WITH cte1 as (
    SELECT * from cdr.Location
)

WITH cte2 as (
    SELECT * from cdr.Location
)

select * from cte1    
union     
select * from cte2

hatadır

Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'WITH'.
Msg 319, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

NB. Ve bu hata ile bir noktalı virgül koyarak denedim

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ';'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ';'.

Muhtemelen konuyla alakalı değil ama bu SQL 2008 üzerinde.

CEVAP
25 ŞUBAT 2009, ÇARŞAMBA


Böyle bir şey olmalı bence

WITH 
    cte1 as (SELECT * from cdr.Location),
    cte2 as (SELECT * from cdr.Location)
select * from cte1 union select * from cte2

Temelde, WITH burada, listeler ve diğer maddeler gibi bir madde "," uygun sınırlayıcı.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Official Android Tips

    Official And

    23 EYLÜL 2009
  • FamilyFeud

    FamilyFeud

    22 AĞUSTOS 2006
  • hotstrikegently

    hotstrikegen

    26 AĞUSTOS 2011