Tuesday 15 June 2010

sql server - Select distinct(columnName) from a table having COALESCE -


I have a table like this that has many records. For example:

HREFTopic Public Prioropathy LastModifiedTime --------------------------------- - -------------------------------------------- //twitter.com / Search? Q =% 23 Happy # Hello St. Patrick's Day 2015-03-17 19: 57: 18.000 //twitter.com/search?q=%23Hiply #Happy St. Patrick's Day 2015-03-17 18: 57: 17.000 // Twitter.com/search?q=%23HappyV #Happy Valentines Day 2015-03-17 17: 57: 15.000

This is my stored procedure

  Announce @ABC ethics (Max) @ SearchCare Newcastle (maximum) @SearchKey = Select 'Happy' Top 10 @abc = COALESCE (@abc + '', '') + '& lt; Li & gt; + '& Lt; One square = "z" href = "'/ .. q.aspx? Q =' + @ of search '' '& gt;' + (Public Useful) + '& lt; / A & gt; & Lt; / Li & gt; ' The popular trademark is + char (10) + char (13), where like '%' + @ SearchKey + '%', LastModifiedTime selects HREFOOPIC @abc  

and outputs ( @ ABC)) =

  & lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happyv" & gt; Happy Valentines Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; One class = "z" href = "../ q.aspx? Q = happy" & gt; Happy St. Patrick's Day & lt; / A & gt; & Lt; / Li & gt;  

But I only require a different (popular top) order by the last modified time and I hope the result will be:

   

I am not able to get different (popularized), but I get all the records. Can someone help me find the right query?

It should do this, and it is better to learn using XML path for string combinations than you use The non-documented variable-making process being done on the Internet is a lot of examples.

  with CTS (Top 10 Popular Topics, Max (Last Modified Time) to choose from popular trades as LMT where 'Halftic'% @ + Search + + 'Group' like LMT Selectively order by DRS) SELECT (SELECT '
  • A class = "z" href = "../ q.aspx? Q =' + @ of search + '" "> gt; Lokprivic + '& lt; /' A ',' Route '(' H 'Varchar (max)')
  • And, what is the price, if you are the top ten popular tropics Have turned back and your If you have handled the build, then you can get better overall performance of the application layer.


    No comments:

    Post a Comment