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 2012 Forums
 Transact-SQL (2012)
 stuff fuction not working properly wjth sql server

Author  Topic 

summer12in
Starting Member

6 Posts

Posted - 2015-01-01 : 23:08:59
I found something very strange...stufff function working with self join but not working with left or right join,.
I have a table

**Id name**

1 samar

1 Harry

2 jack

I want the output as

**Id name**

1 samar Harry

2 jack

The below query works fine with self join

Select b.id, stuff ((select ` ` + a.name from #test a where a.id = b.id
for xml path (``)),1,1,``)

From #test b

Group by id


But when i do right join i get error _ invalid object name `b`. Please let me know where i am going wrong....

Select b.id, stuff ((select ` ` + a.name from #test a
right join b on b.id = a.id for xml path (``),1,1,``)

From #test b

Group by id



Samarjeet

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-02 : 10:05:16
you have to from clauses in your query. That is invalid syntax. What you want is to change the join a little bit. Change it to: join #temp as b
Go to Top of Page
   

- Advertisement -