Why Do I Get SQL Syntax Errors In My Query? -
i trying retrieve data in following format:
story | story type | creation date | company role | tag 1 | tag 2 | tag 3 negative iii | negative | 21/02/2011 | business analyst | project duration | team size | process negative ccc | negative | 22/02/2011 | admin | workspace layout | organisational | process
instead of:
story | storycategoryid | creationdate | companyrole | name negative iii | 1 | 21/02/2011 | business analyst | project duration negative iii | 1 | 21/02/2011 | business analyst | team size negative iii | 1 | 21/02/2011 | business analyst | process negative ccc | 1 | 22/02/2011 | admin | workspace layout negative ccc | 1 | 22/02/2011 | admin | organisational , reporting structure negative ccc | 1 | 22/02/2011 | admin | process
but getting following errors:
1) incorrect syntax near keyword as,
2) incorrect syntax near z
here's sql, please help!
select story, case storycategoryid when 1 'negative' when 0 'positive' else cast(storycategoryid varchar(10)) storycategoryid, creationdate, companyrole, max(case when z.minname = af2.name af2.name else '' end) tag1 , max(case when z.minname <> af2.name , z.maxname <> af2.name af2.name else '' end) tag2, max(case when z.maxname = af2.name af2.name else '' end) tag3 ( select s.story , s.storycategoryid , convert(varchar(10), s.creationdate, 103) creationdate , m.companyrole , af.agilefactorid , min(af.name) minname , max(af.name) maxname story s inner join projectiterationmember pm on pm.projectiterationmemberid = s.projectiterationmemberid inner join iterations on i.projectiterationid = pm.projectiterationid inner join member m on m.memberid = pm.memberid inner join projectstoryfactors psf on psf.storyid = s.storyid inner join agilefactors af on af.agilefactorid = psf.agilefactorid i.projectid = '" + proj_id + "'" group s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103), m.companyrole, af.agilefactorid ) z inner join agilefactors af2 on af2.agilefactorid = z.agilefactorid group story, storycategoryid, creationdate, companyrole
that sql unreadable:
select story, case storycategoryid when 1 'negative' when 0 'positive' else cast(storycategoryid varchar(10)) storycategoryid, creationdate, companyrole, max(case when z.minname = af2.name af2.name else '' end) tag1 , max(case when z.minname <> af2.name , z.maxname <> af2.name af2.name else '' end) tag2, max(case when z.maxname = af2.name af2.name else '' end) tag3 ( select s.story , s.storycategoryid , convert(varchar(10), s.creationdate, 103) creationdate , m.companyrole , af.agilefactorid , min(af.name) minname , max(af.name) maxname story s inner join projectiterationmember pm on pm.projectiterationmemberid = s.projectiterationmemberid inner join iterations on i.projectiterationid = pm.projectiterationid inner join member m on m.memberid = pm.memberid inner join projectstoryfactors psf on psf.storyid = s.storyid inner join agilefactors af on af.agilefactorid = psf.agilefactorid i.projectid = '" + proj_id + "'" group s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103), m.companyrole, af.agilefactorid ) z inner join agilefactors af2 on af2.agilefactorid = z.agilefactorid group story, storycategoryid, creationdate, companyrole;
at least organize structural keywords visible:
select story, case storycategoryid when 1 'negative' when 0 'positive' else cast(storycategoryid varchar(10)) storycategoryid, creationdate, companyrole, max(case when z.minname = af2.name af2.name else '' end) tag1, max(case when z.minname <> af2.name , z.maxname <> af2.name af2.name else '' end) tag2, max(case when z.maxname = af2.name af2.name else '' end) tag3 (select s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103) creationdate, m.companyrole, af.agilefactorid, min(af.name) minname, max(af.name) maxname story s join projectiterationmember pm on pm.projectiterationmemberid = s.projectiterationmemberid join iterations on i.projectiterationid = pm.projectiterationid join member m on m.memberid = pm.memberid join projectstoryfactors psf on psf.storyid = s.storyid join agilefactors af on af.agilefactorid = psf.agilefactorid i.projectid = '" + proj_id + "'" group s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103), m.companyrole, af.agilefactorid) z join agilefactors af2 on af2.agilefactorid = z.agilefactorid group story, storycategoryid, creationdate, companyrole
the notation '" + proj_id + "'"
suggests extracted string in programming language; open invitation sql injection. in pure sql context, syntactically invalid; have stray double quote @ end.
Comments
Post a Comment