| Author |
Topic |
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2008-12-30 : 06:48:14
|
| the folowing are my tables:tblImage: table values: imageid - bigint 1 jesus.jpgimageurl- varchar(max) 2 sachin.jpgtblUserDetail: userid- bigint 1 sql 1,2username - varchar(50)imageid-textso my out put should be name imageurlsql jesus.jpgsql sachin.jpgplease give me some sample query to achieve this please |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-30 : 06:59:17
|
| SELECT t2.username,t1.imageurlFROM tblimage t1INNER JOIN tblUserDetail t2 ON t1.imageid LIKE t2.imageidJai Krishna |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2008-12-30 : 07:05:50
|
quote: Originally posted by raky select u.username as name,i.imageurlfrom tblUserDetail u inner join tblImage i on u.imageurl = i.imageurl and i.imageid = u.imageid
I think imageid in tblImage as text datatype so please check it once... |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-30 : 07:11:49
|
| select u.username,i.imageurl from tblImage i inner join tbluserdetail u on ('%,' + stuff((select ','+ cast(imageid as varchar(32)) from tblimage for xml path ('')),1,1,'') + ',%') like (select ('%,' + cast(imageid as varchar(32)) + ',%') from tbluserdetail)try this |
 |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2008-12-30 : 07:16:34
|
| if my table structure is wrong please give me sample table structure for my need please |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-30 : 07:21:23
|
| hi, sqloverno ur getting the required output once check the above query |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 11:26:04
|
| have you heard of normalization? why are you storing values as comma separated in imageid field? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 11:55:17
|
| [code]SELECT m.username,i.imageurlFROM(SELECT t.userid,t.username,f.ValFROM tblUserDetail tCROSS APPLY dbo.ParseValues(t.imageid,',') f)mINNER JOIN tblImage iON m.Val=i.imageid[/code]parsevalues can be found herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113563 |
 |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2008-12-31 : 00:44:13
|
| thank you friends for the efficient answers |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-31 : 00:55:12
|
you're welcome |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-31 : 01:08:32
|
| WelcomeJai Krishna |
 |
|
|
|