Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Can my complex SQL Query be written different

Author  Topic 

mshsilver
Posting Yak Master

112 Posts

Posted - 2011-05-24 : 05:32:32
Hi All,

I am using this query to get the results i need from my SQL database. and it is working in SQL management studio but when i put it in a bespoke web application sql browser which i have to do it says there is "Incorrect syntax near the keyword 'with'"

Is there another way of writing this query to simplify it?

Thanks for looking!



with cteDelegates ( company, postalcode, last_hs, next_hs, risk_level, sct1, sct2, training_provider, rown) as (Select wce_course_delegate_link.edrs_no, wce_contact.company, postalcode, wce_contact.last_hs, wce_contact.next_hs, wce_contact.risk_level, wce_course_delegate_link.sct1, wce_course_delegate_link.sct2, wce_course_delegate_link.training_provider, ROW_NUMBER() OVER (PARTITION BY wce_course_delegate_link.edrs_no ORDER BY wce_course_delegate_link.edrs_no, wce_course_delegate_link.sct1) from wce_course_delegate_link left join wce_contact on wce_course_delegate_link.edrs_no = wce_contact.edrs where wce_course_delegate_link.end_date is null and wce_contact.record_type = 'company') Select edrs_no, company, postalcode, last_hs, next_hs, risk_level, sct1, sct2, training_provider from cteDelegates where rown = 1 order by edrs_no


raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-05-24 : 05:37:26
May be you missed ; before your with

;with

If its not working then write stored procedure for it and call this stored procedure
Or post table structure with some data and what output you want.

In Love... With Me!
Go to Top of Page

mshsilver
Posting Yak Master

112 Posts

Posted - 2011-05-24 : 06:03:58
Amazing, it was the; thank you so much for pointing that one out, it doesn’t need in SQL directly. Thanks again ?
Go to Top of Page
   

- Advertisement -