Hi,
I am trying to concat an int with an nvarchar in my select:
select distinct(id + name)
from load
where name not like '%test%'
but I am getting an error saying:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the nvarchar value '灪愭楮敭' to a column of data type int.
My question is: how do you concat int and string in MS SQL Server. The equivalent in Oracle would be ||, I think.
Thanks for any help.
Mongodid you try this --
select distinct(cast(id as nvarchar) + name) ...
Showing posts with label distinct. Show all posts
Showing posts with label distinct. Show all posts
Tuesday, March 27, 2012
Thursday, March 8, 2012
COMPLEX sql query PLEASE HELP!
I cant get "order by" to work in this sql query..
I use this query:
SELECT TOP 12 name, total FROM (SELECT name, total = COUNT(*) FROM products WHERE kat = 'music' GROUP BY name) AS groupedSet ORDER BY NEWID()
The subquery generates a set in the output format that you want, the main query just orders it randomly and restricts it to 12 rows.
Does this help?
|||Thanks for your answer and thanks for your help It worked perfect.
you are KING!!!
I use this query:
"SELECT DISTINCT TOP 12 name,total = COUNT(*) FROM products where kat = 'music' group by namn"
and I want to add this some where to get 12 random records: "ORDER BY NewID()"
I tried this:"SELECT DISTINCT TOP 12 name,total = COUNT(*) FROM products where kat = 'music' group by namn ORDER BY NewID()""
but get the error:
"ORDER BY items must appear in the select list if SELECT DISTINCT is specified"
I can′t figure out how I should write the query..
Somebody have any ideas??
/Radiwoi
SELECT TOP 12 name, total FROM (SELECT name, total = COUNT(*) FROM products WHERE kat = 'music' GROUP BY name) AS groupedSet ORDER BY NEWID()
The subquery generates a set in the output format that you want, the main query just orders it randomly and restricts it to 12 rows.
Does this help?
|||Thanks for your answer and thanks for your help It worked perfect.
you are KING!!!
Subscribe to:
Posts (Atom)