SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Complex code
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

SwePeso
Patron Saint of Lost Yaks

Sweden
30249 Posts

Posted - 01/17/2007 :  04:52:58  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT		x.[User],
		x.Location,
		COUNT(*) AS Apps
FROM		(
			SELECT	[User],
				Location,
				[Applications 1] AS App
			FROM	Working
			UNION
			SELECT	[User],
				Location,
				[Application 2]
			FROM	Working
			UNION
			SELECT	[User],
				Location,
				[Application 3]
			FROM	Working
			UNION
			SELECT	[User],
				Location,
				[Application 4]
			FROM	Working
			UNION
			SELECT	[User],
				Location,
				[Application 5]
			FROM	Working
		) AS x
GROUP BY	x.[User],
		x.Location
ORDER BY	3 DESC


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Jaybee from his castle
Yak Posting Veteran

64 Posts

Posted - 01/17/2007 :  06:28:42  Show Profile  Reply with Quote
Peso - I just realised something - the latest scripts don't reference the CitrixApps table!!!

Do you remember I wanted to group what users had 1 application common to citrixapps.citrixapps, then 2 applications, then 3 etc (and ideally their location) ??

Cheers,





Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30249 Posts

Posted - 01/17/2007 :  06:39:20  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Here it is anyway, since I figured out you never will be able to solve this by yourself.

First, create a VIEW with this
CREATE VIEW dbo.vwSomeData
AS

SELECT		x.[User],
		x.Location,
		COUNT(*) AS Apps
FROM		(
			SELECT		[User],
					Location,
					[Applications 1] AS App
			FROM		Working
			INNER JOIN	CitrixApps ON CitrixApps.CitrixApps = Working.[Applications 1]
			UNION
			SELECT		[User],
					Location,
					[Application 2]
			FROM		Working
			INNER JOIN	CitrixApps ON CitrixApps.CitrixApps = Working.[Application 2]
			UNION
			SELECT		[User],
					Location,
					[Application 3]
			FROM		Working
			INNER JOIN	CitrixApps ON CitrixApps.CitrixApps = Working.[Application 3]
			UNION
			SELECT		[User],
					Location,
					[Application 4]
			FROM		Working
			INNER JOIN	CitrixApps ON CitrixApps.CitrixApps = Working.[Application 4]
			UNION
			SELECT		[User],
					Location,
					[Application 5]
			FROM		Working
			INNER JOIN	CitrixApps ON CitrixApps.CitrixApps = Working.[Application 5]
		) AS x
GROUP BY	x.[User],
		x.Location
And then all you have to do is to write
SELECT	[User],
	Location
FROM	dbo.vwSomeData
WHERE	Apps = 1 -- Or 2, Or 0, or 5...

Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 01/17/2007 07:51:27
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30249 Posts

Posted - 01/17/2007 :  06:40:57  Show Profile  Visit SwePeso's Homepage  Reply with Quote
If you are not satisfied with this, you will have to post some sample data and your expected output based on your provided sample data!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Jaybee from his castle
Yak Posting Veteran

64 Posts

Posted - 01/17/2007 :  07:47:10  Show Profile  Reply with Quote
I think i should have said, "Applications 1" is NOT a column of users who have one application in common - if a users row has 5 applications listed, they will each be in Application 1, etc Application 2 etc.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30249 Posts

Posted - 01/17/2007 :  07:52:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
???


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

eyechart
Flowing Fount of Yak Knowledge

USA
3575 Posts

Posted - 01/17/2007 :  12:00:41  Show Profile  Reply with Quote
quote:
Originally posted by Jaybee from his castle

I think i should have said, "Applications 1" is NOT a column of users who have one application in common - if a users row has 5 applications listed, they will each be in Application 1, etc Application 2 etc.






seriously, you need to start thinking on your own. I think this thread is done.


-ec
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000