Click here to Skip to main content
15,900,254 members
Home / Discussions / Database
   

Database

 
GeneralRe: Normalization Pin
CPallini20-Jun-08 0:00
mveCPallini20-Jun-08 0:00 
GeneralRe: Normalization Pin
Jerry Hammond21-Jun-08 7:44
Jerry Hammond21-Jun-08 7:44 
GeneralRe: Normalization Pin
CPallini22-Jun-08 0:44
mveCPallini22-Jun-08 0:44 
QuestionProblem in Query Pin
garga119-Jun-08 19:06
garga119-Jun-08 19:06 
AnswerRe: Problem in Query Pin
Marek Grzenkowicz19-Jun-08 21:31
Marek Grzenkowicz19-Jun-08 21:31 
AnswerRe: Problem in Query Pin
Anurag Gandhi19-Jun-08 22:00
professionalAnurag Gandhi19-Jun-08 22:00 
GeneralRe: Problem in Query Pin
garga120-Jun-08 1:39
garga120-Jun-08 1:39 
AnswerRe: Problem in Query Pin
Ashfield20-Jun-08 0:58
Ashfield20-Jun-08 0:58 
What you are trying to achieve (I think) is known as pivoting. This sample should point you in the right direction.

/* create test table and populate */

 

create table UserArea(Country varchar(20))

insert into UserArea
select 'India'
union all
select 'USA'
union all
select 'India'
union all
select 'UK'


/* now the actual code */

DECLARE @SQL nvarchar(4000)

SET @SQL=''   

SELECT @SQL= @SQL +

'SUM(CASE WHEN Country=''' + a.Country + ''' THEN 1 ELSE 0 END) AS [' + a.Country + '],'

FROM (select distinct Country from UserArea) as a

select @SQL = left(@SQL,len(@SQL)-1)

SET @SQL='SELECT ' + @SQL + ' FROM UserArea'

EXEC(@SQL)

/* tidy up */

drop table  UserArea


Bob
Ashfield Consultants Ltd

AnswerRe: Problem in Query Pin
Niraj_Silver26-Jun-08 0:06
Niraj_Silver26-Jun-08 0:06 
QuestionWhy would you ever designate a primary key as non-clustered? Pin
Marc Clifton19-Jun-08 9:29
mvaMarc Clifton19-Jun-08 9:29 
AnswerRe: Why would you ever designate a primary key as non-clustered? Pin
SomeGuyThatIsMe19-Jun-08 14:41
SomeGuyThatIsMe19-Jun-08 14:41 
GeneralRe: Why would you ever designate a primary key as non-clustered? [modified] Pin
Alsvha19-Jun-08 18:14
Alsvha19-Jun-08 18:14 
GeneralRe: Why would you ever designate a primary key as non-clustered? Pin
SomeGuyThatIsMe20-Jun-08 0:02
SomeGuyThatIsMe20-Jun-08 0:02 
AnswerRe: Why would you ever designate a primary key as non-clustered? Pin
Alsvha19-Jun-08 18:21
Alsvha19-Jun-08 18:21 
AnswerRe: Why would you ever designate a primary key as non-clustered? Pin
econner26-Jun-08 17:02
econner26-Jun-08 17:02 
Questionjoining two queries Pin
csp19-Jun-08 2:09
csp19-Jun-08 2:09 
AnswerRe: joining two queries Pin
Blue_Boy19-Jun-08 3:44
Blue_Boy19-Jun-08 3:44 
GeneralRe: joining two queries Pin
A Wong19-Jun-08 3:50
A Wong19-Jun-08 3:50 
GeneralRe: joining two queries Pin
Blue_Boy19-Jun-08 3:52
Blue_Boy19-Jun-08 3:52 
GeneralRe: joining two queries Pin
A Wong19-Jun-08 4:48
A Wong19-Jun-08 4:48 
AnswerRe: joining two queries Pin
Niraj_Silver26-Jun-08 0:15
Niraj_Silver26-Jun-08 0:15 
QuestionThe multipart identifier could not be bound Pin
JacquesDP18-Jun-08 23:20
JacquesDP18-Jun-08 23:20 
AnswerRe: The multipart identifier could not be bound Pin
Blue_Boy19-Jun-08 1:05
Blue_Boy19-Jun-08 1:05 
GeneralRe: The multipart identifier could not be bound Pin
JacquesDP19-Jun-08 1:30
JacquesDP19-Jun-08 1:30 
GeneralRe: The multipart identifier could not be bound Pin
Blue_Boy19-Jun-08 3:42
Blue_Boy19-Jun-08 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.