|
Not sure I've understood you properly, but your subquery doesn't look correct.
So try something like this:
SELECT dbo.ContactMaster.BmcCustKey
,Sum(CASE WHEN dbo.LocationAccessGrant.CanAccessLocation = 1
THEN 1
ELSE 0
END) accesscount
FROM dbo.ContactMaster
LEFT OUTER JOIN dbo.LocationAccessGrant
ON dbo.ContactMaster.CompanyID = dbo.LocationAccessGrant.CompanyID
AND dbo.ContactMaster.ContactIdentity = dbo.LocationAccessGrant.ContactIdentity
GROUP BY dbo.ContactMaster.BmcCustKey
,dbo.LocationAccessGrant.CanAccessLocation
ORDER BY dbo.ContactMaster.BmcCustKey It should take care of your null values
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
Hi,
How many concurrent we can have in SQL Server 2005 Express?
Does it make difference with the operating system like windows server 2003/2008 or winxp pro?
And I am getting error while connecting to the sql server 2005 express that the remote server has refused the remote connection (Error no. 26) though it was working fine before couple of days (I have enabled the remote connection via/pipeline/tcpip and also added in firewall exception port 1433. It was working fine before).
After that I have just restarted my server and its works fine! What can be wrong in this? May be the number of concurrent connection has reached!
Thanks,
Divyesh
|
|
|
|
|
I don't see a connection limitation in SQL server express, but there are indeed tcp connection limitations in windows XP. (Microsoft wants you to buy the server if you're doing server work).
|
|
|
|
|
This[^] fixes that little problem.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
No, not really. This was introduced to limit the number of half-open connections (typically session in the SYN_WAIT state). A number of worms were rampant at that time, and they opened oodles of connections to systems simultaneously. P2P systems typically do likewise, so this patch was developed to allow P2P to run. I doubt that this is the OP's problem.
I was thinking more in the line of this[^], but MS seems to imply that they don't enforce the inbound connection limit, except for SMB operations. So if the SQL server is connecting though named pipes, yes it would be a problem, but normal TCP connections should be okay.
|
|
|
|
|
hi,
I was trying to update the Cyrillic characters · Serbian characters in sql server database, but everytime i shows ??? after updation
Please suggest something.
Thanks
|
|
|
|
|
Do you use VARCHAR or NVARCHAR? Only NVARCHAR will do!
|
|
|
|
|
Thanks for replying...
If I have to search for keyword abcurlф in the table
what should be the query in this case?
Presently it is not displaying any result if i search even only with ф
and displays those records which have ? character
|
|
|
|
|
In the Employees table of Northwind database, I changed the FirstName of an entry to "abcurlф". Now I do in SQL Enterprise Manager:
SELECT *
FROM Employees
WHERE (FirstName LIKE N'%ф%')
and that returns exactly the row where I made that change.
Note that an "N" is required before the search term - LIKE '%ф%' does not work.
|
|
|
|
|
I have a database with a master - detail relationshio between two tables. The database is basically a snapshot in time for each office. so imagine that my master table is:
id (auto increment), date, office_id
1 , 2010-4-1, 100
2 , 2010-4-2, 100
3 , 2010-4-3, 100
4 , 2010-4-4, 100
5 , 2010-4-1, 101
6 , 2010-4-2, 101
7 , 2010-4-3, 101
8 , 2010-4-4, 101
I want to get the id number for the last update date from the master table so I did the following:
SELECT id, max(upload_date) as upload_date, office_id from master group by office_id
What I want is the id number associated with the latest date, so I WANT
id, date, office
4, 2010-4-4,100
8, 2010-4-4,101
What I get is:
1, 2010-4-4,100
5, 2010-4-4,101
I get the max date, but the first id number. Normally I'd do a cursor in a procecure to get it, but the ISP has to grant the pivs each time the sp is modified so I am trying to do this in a simple query since it is called from php.
As a work around, I am doing a max(id) as well since I figured that the highest id would always be associated with the latest date, but I don't want to make that assumption.
Does anyone know how to build the query correctly to get the id associated with the latest date?
|
|
|
|
|
I'm not sure, I think you need to add some sorting, try "ORDER BY date DESC" on top of your grouping.
|
|
|
|
|
I'm little bit confused; are we trying to get the current inserted / updated data using the dateTime criteria?
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
No, I was suggesting to get things sorted within each group, but MySQL isn't accepting a "ORDER BY ... GROUP BY ..." qualification.
|
|
|
|
|
Yep, I got your point.
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
You can try SQL SCOPE_IDENTITY function to get the last identity value inserted into an identity column in the same scope. Or you can also try in a trigger which something like:
DECLARE @id int = 0
SET @id = (SELECT id FROM INSERTED )
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
I wasn't sure what MySQL supports so I kept out of it!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Try the following
select a.id
,a.upload_date
,a.office_id
from ( select max(m.upload_date) max_upload_date
,m.office_id office_id
from master m
group by m.office_id
) tmp
,master a
where a.upload_date = tmp.max_upload_date
and a.office_id = tmp.office_id
;
You need to be joining the table on itself, though it is more a view on itself.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Hi,
Is there any way to find all stored procedures which are being called inside the main procedure? This can go deeper at last level inside the main one. I have tried the available option for "right click" > "View Dependancies" but it does not show the procedures called by EXEC statement. Please correct me if I am wrong here.
My problem is - I have a procedure which calls multiple other procedures inside it. Also these called procedures again might have called other procedures inside them. Now I need to find a list of all such dependent procedures for my main procedure.
Thanks in advance for your inputs!
Anil
|
|
|
|
|
There is an answer to this on SQLServerCentral.com here[^]. You might have to sign up to view it, can't remember, but it is a reputable and useful site.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
Try the following:
Link 1 : sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/[^]
Or
DECLARE @StringToSearch NVARCHAR(MAX)
SET @StringToSearch = 'ENTER_SP_TO_SEARCH'
SELECT
[name],
(
SELECT
OBJECT_DEFINITION(obj2.object_id) AS [text()]
from sys.all_objects obj2
where obj2.object_id = obj1.object_id
FOR XML PATH(''), TYPE
) AS Obj_text,
[type] as ObjType
FROM sys.all_objects obj1
WHERE OBJECT_DEFINITION(object_id([name])) LIKE '%' + @StringToSearch + '%'
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hello. I am getting the following error when trying to connect:
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (.Net SqlClient Data Provider)"
1) I tried seeing what services are running and nothing with SQL Server is listed.
2) I ran the Surface Area Configuration and the following message immediately pops up:
"No SQL Server 2005 components were found on the specified computer. Either no components are installed, or you are not an administrator on this computer. (SQLSAC)"
What in blazes is going on?
Thanks.
|
|
|
|
|
This tends to be a misleading, catch all error message. Assuming you actually have SQL installed and can see the database in SSMS then I would delete the credentials you are using and re create them. This may be cause by a restore from another server corrupting the user details.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I’m trying to display a list of shops each with 3 random items from their shop, if they have 3 or more listings, that are actively advertising. I have 3 tables: one for the shops – “Shops”, one for the listings – “Listings” and one that tracks active advertisers – “AdShops”.
Using the below statement, the listings returned are random however I’m not getting exactly 3 listings (rows) returned per shop.
SELECT AdShops.ID, Shops.url, Shops.image_url,
Shops.user_name AS shop_name, Shops.title, L.listing_id AS listing_id,
L.title AS listing_title, L.price as price,
L.image_url AS listing_image_url, L.url AS listing_url
FROM AdShops INNER JOIN
Shops ON AdShops.user_id = Shops.user_id INNER JOIN
Listings AS L ON Shops.user_id = L.user_id
WHERE (Shops.is_vacation = 0 AND Shops.listing_count > 2 AND
L.listing_id IN
(SELECT TOP 3 L2.listing_id
FROM Etsy_Listings AS L2
WHERE (L2.user_id = L.user_id)
ORDER BY NEWID()
)
)
ORDER BY Shops.shop_name
When 'ORDER BY NEWID()' is removed, I get exactly 3 rows returned per shop but it's the first 3 listings and not random - I’m stumped. Anyone have any ideas on how to fix it?
The ideal solution would be one record per store with the 3 listings (and associated data) were in columns and not rows – is this possible?
|
|
|
|
|
Thanks to Lieven stackoverflow.com[stackoverflow.com] for the key to solving the problem. Full solution is as follows:
SELECT AdShops.ID, Shops.url, Shops.image_url,
Shops.user_name AS shop_name, Shops.title, L.listing_id AS listing_id,
L.title AS listing_title, L.price as price,
L.image_url AS listing_image_url, L.url AS listing_url
FROM AdShops INNER JOIN
Shops ON AdShops.user_id = Shops.user_id INNER JOIN
Listings AS L ON Shops.user_id = L.user_id
WHERE (Shops.is_vacation = 0 AND Shops.listing_count > 2 AND
L.listing_id IN
(SELECT listing_id
FROM
(SELECT l2.user_id , l2.listing_id, RowNumber = ROW_NUMBER()
OVER (PARTITION BY l2.user_id ORDER BY NEWID())
FROM Listings l2 INNER JOIN
(SELECT user_id
FROM Listings
GROUP BY user_id
HAVING COUNT(*) >= 3
) cnt ON cnt.user_id = l2.user_id
) l2
WHERE l2.RowNumber <= 3 and L2.user_id = L.user_id
)
)
ORDER BY Shops.shop_name
Anyone have any ideas on how to merge the 3 rows into a single row with the 3 listings moved into columns (several colums per listing) ????
|
|
|
|
|
Here we go again, this article may be of use Pivot two or more columns in SQL Server 2005[^]
This query basically represents the "inner" query in the article, now you need to extract the column labels to be pivotted on and write the outer query. I would stuff this query into a table var or view and work from there.
Never underestimate the power of human stupidity
RAH
|
|
|
|