hello,
i have this sql query it works fine. if you see in the query there is a LIKE operation and variable in like operaiton is "Key."
i cannot select top 1 record the out put can be multiple string that has to be search in like operator so any matching result come
like
declare @key
set @key (select tagname from tagtable) --- this table can return many strings in row like
cat
apple
cow
all this tagname should pass in below query and if these word exist in descripiton column so it should return that rows
select description from post where description like '%+@key %'
SELECT TOP (20) dbo.Profile.firstname, dbo.Profile.lastname, ISNULL(dbo.Post.Head, '') AS Head, dbo.Post.[File], REPLACE(dbo.Post.[File], '~', '') AS video, format(dbo.Post.InsertDate, 'MMM/dd/yyyy, hh:mm:ss') AS InsertDate, dbo.Post.Points,
dbo.Post.Status, dbo.Post.ext, ISNULL(dbo.Profile.image, dbo.Alphabet.Image) AS profileimage, dbo.Profile.UserName, dbo.Post.PostId, ISNULL(totalcomments.total, 0) AS totalcomment, dbo.CreateWorld.WorldName,
dbo.CreateWorld.CreateYourWorldId, REPLACE(REPLACE(REPLACE(REPLACE(CAST(ISNULL(dbo.Post.Head, 'Feeling...') AS nvarchar(25)), ' ', '-'), '&', '-'), '/', '-'), ' ', '') AS Header,
REPLACE(REPLACE(REPLACE(REPLACE(CAST(ISNULL(dbo.CreateWorld.WorldName, 'Community') AS nvarchar(25)), ' ', '-'), '&', '-'), '/', '-'), ' ', '') AS GHeader
FROM dbo.Post INNER JOIN
dbo.Profile ON dbo.Post.ProfileId = dbo.Profile.ProfileId LEFT OUTER JOIN
dbo.CreateWorld ON dbo.Post.CreateYourWorldId = dbo.CreateWorld.CreateYourWorldId LEFT OUTER JOIN
dbo.Alphabet ON CAST(dbo.Profile.firstname AS nvarchar(1)) = dbo.Alphabet.Alphabet LEFT OUTER JOIN
(SELECT COUNT(*) AS total, PostID
FROM dbo.PostComment
GROUP BY PostID) AS totalcomments ON dbo.Post.PostId = totalcomments.PostID
WHERE (ISNULL(dbo.Post.Head, N'') LIKE N'%' + @key + N'%') AND (dbo.Post.Status = N'Active') AND (dbo.Post.PostId NOT IN
(SELECT TransactionId
FROM dbo.TagViews
WHERE (UserName = @Username) AND (Module = 'Post')))
ORDER BY dbo.Post.PostId DESC
in the "Key" variable i want to pass another sql statement how to do that
this sql select should be pass to above sql query above
@key = select tagname from tagsearches
where username=@UserName and module= 'Post'