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)
 error in query

Author  Topic 

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-11-20 : 07:38:14
Good day everybody.

Next query has error, Can we help me pleas?

SELECT
VCisOrgOdpOs.stredisko,c.cisloorg,c.ico,c.nazev,
predajca = CAST STUFF((SELECT
DISTINCT ', '+convert(varchar(10),CONVERT(int, e.Stredisko),','+e.prijmeni)
FROM hvw_predajcovia r
INNER JOIN tabciszam e
ON e.cislo=r.cislozam
WHERE x.cisloorg=c.cisloorg
FOR XML PATH('')),1,1,'') as nvarchar(25))

FROM tabcisorg c
LEFT OUTER JOIN TabCisZam VCisOrgOdpOs ON c.OdpOs=VCisOrgOdpOs.ID

query comes from this that is completely correct.
I want convert +e.stredisko on "+convert(varchar(10),CONVERT(int, e.Stredisko)"
from this correct query:

SELECT
VCisOrgOdpOs.stredisko,c.cisloorg,c.ico,c.nazev,STUFF((SELECT
DISTINCT ','+e.stredisko,','+e.prijmeni
FROM hvw_predajcovia r
INNER JOIN tabciszam e
ON e.cislo=r.cislozam
WHERE r.cisloorg=c.cisloorg
FOR XML PATH('')),1,1,'') as predajca

FROM tabcisorg c
LEFT OUTER JOIN TabCisZam VCisOrgOdpOs ON c.OdpOs=VCisOrgOdpOs.ID

big thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-20 : 07:41:48
Missing left bracket - see in red below
SELECT 
VCisOrgOdpOs.stredisko,c.cisloorg,c.ico,c.nazev,
predajca = CAST( STUFF((SELECT
DISTINCT ', '+convert(varchar(10),CONVERT(int, e.Stredisko),','+e.prijmeni)
....
Go to Top of Page

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-11-20 : 07:50:33
not

error is somewhere in syntax

but thanks
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-20 : 08:01:48
You do need the left bracket that I highlighted in my previous post. In addition, it seems like there is an error here:
DISTINCT ', '+convert(varchar(10),CONVERT(int, e.Stredisko),','+e.prijmeni)
It perhaps should be something like this
DISTINCT ', '+convert(varchar(10),CONVERT(int, e.Stredisko))+','+e.prijmeni
But I am only guessing - what are you trying to get using the two convert functions? Regardless, if e.Stredisko is not something that can be converted to an integer, the query would fail.
Go to Top of Page

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-11-20 : 09:11:30
not

Forget broader problem is somewhere in the syntax
I must solved myself

thanks for trying

I closed topic
Go to Top of Page
   

- Advertisement -