|
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
|
|
|
|
|
|
Hi all, I have a MSSQL database with Godaddy, and I have access using the SQL Server Managements Studio, and of course their Hosting center interface with a web browser.
I need a more robust backup setup. Currently I would have to manually initiate a backup.
-Is there a way to automate a backup using The Sql Server Management Studio? Perhaps from my client PC (COM, DLL)?
-I can't use the BACKUP command statement as the server is attempting to create the backup file on THEIR servers. The only information I'm using the database is table data. If using .NET along with the SQL database, are there any methods (that would be reasonably affective) to SELECT statement for each table in db. Then export this database to csv or other format.
Appreciate your help.
|
|
|
|
|
How about creating the back on their servers and then ftping the backup files to your server/computer?
|
|
|
|
|
IMO, the only place where you can backup the databases on a server is on the server itself. What you can do is to write a script to execute the BACKUP command and FTP the file from the server to your PC/Laptop.
modified on Tuesday, May 31, 2011 7:11 AM
|
|
|
|
|
If I may ask, how is your answer different from mine?
|
|
|
|
|
I did not read your post.
|
|
|
|
|
No problem
|
|
|
|
|
Hi,
Can anyone provide me with a link for tutorials on stored procedures?
Thanks
Cheers
Nikhil
|
|
|
|