|
Without sample data its hard to give you a best solution, give this a try
select distinct a.typeid, (select top 1 details from auditlog where typeid = a.typeid) [details]
from auditlog
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Hi
When building a website, which method will increase performance, Using one connection in a global variable and using it to execute all queries or opening a connection for each user (Session)?
Please advice.
|
|
|
|
|
|
Normally the second.
But, again normally, there are far better reasons for doing that than performance.
|
|
|
|
|
I want to find distinct country and count of each country from a country table.
How should I do?
Result:
Country | Count
Japan | 10
UK | 8
Canada | 12
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
|
|
|
|
|
select country, count(country) from countrytable
group by country
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
|
|
|
|
|
Thank You, I missed group by.
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
|
|
|
|
|
Is is not working for null country and does not give correct count
Hepl ?
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
|
|
|
|
|
Use isnull for your count field.
e.g
select country, count(isnull(country,0)) from countrytable
group by country
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
If country is null, it need not be shown.
I would say
select country, count(country) from countrytable
where country is not null
group by country
|
|
|
|
|
Hi. I have a website (IIS) that clients make queries to the server which could take up to a minute to get the results. With that i have no problem. but when a different user(!) on IIS tries to query even a different table he will hang until the first user is responded. When i enter SSMS i can query and get immediate result. Does anyone have a solution for this?
I must mention, that the SQL Connection in the website is not unique per request or per client, it is one connection for all requests, any chance that this is the reason for the wait?
Thanks.
Eli
|
|
|
|
|
Eli Nurman wrote: any chance that this is the reason for the wait?
yes.
|
|
|
|
|
Hi, Thanks for you reply. So how can i solve this? Why are queries via SSMS not affected?
|
|
|
|
|
Eli Nurman wrote: So how can i solve this
Use more than one connection.
Eli Nurman wrote: Why are queries via SSMS not affected?
Because it is using a different connection.
|
|
|
|
|
Hi,
Please suggest me any website which offers free training videos for programming SQL server 2005 or 2008...
|
|
|
|
|
|
i have an interesting question for you guys.
SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
FROM SCHOOLPHOTO SP
INNER JOIN SCHOOL S
ON SP.SCHOOLID = SP.SCHOOLID
WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS)
the Photo Field is an Image Datatype Field, i now you can use them in a Distinct or group by , How can i go by have that field there without casting it , because if i cast it it will not work together in Silverlight or any other image control.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
How about generating a hash code for your image and store that value in your table along with the image. You could then use the hash code in your group by clause.
check this article out ...
http://www.vcskicks.com/image-hash.php[^]
It was the first thing that popped up in my Google search.
Good luck.
|
|
|
|
|
I need a Solution in T-SQL
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
What version of SQL Server are you using? If it's sufficiently advanced, you could apply this as a CLR Trigger.
|
|
|
|
|
I am SQL 2008
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Then it's job done. You can use a SQL CLR trigger and store the hash when the image is inserted or updated.
|
|
|
|
|
this did the Job
;with cteSchools as (SELECT DISTINCT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME]
FROM SCHOOL S
WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS))
SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
FROM cteSCHOOLS S
CROSS APPLY (Select TOP (1) PHOTO from SchoolPhoto SP
WHERE SP.SCHOOLID = S.SCHOOLID
ORDER BY SCHOOLID DESC) SP
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Use the T-SQL function hashbytes like this:
select hashbytes('MD5', 'your value')
|
|
|
|
|
I'm trying to export the results of a stored procedure to a csv, here's what I've got:
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\bcp.exe" myDb.dbo.spExport out "Data.csv" -T -Slocalhost -t";" -c
It keeps telling me "Invalid object name 'myDb.dbo.spExport'."
Other stored procedures don't work either and none require parameters.
Pointing to a table works so I thought I was pointing to at the SP's the right way.
What am I doing wrong?
-Nevermind, got it working:
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\bcp.exe" myDb.dbo.spExport queryout "Data.csv" -T -Slocalhost -t";" -c
modified on Tuesday, May 31, 2011 10:08 AM
|
|
|
|