Click here to Skip to main content
15,902,938 members
Home / Discussions / Database
   

Database

 
QuestionSSRS - dynamic columns depending on client parameter Pin
Danpeking24-May-17 23:33
Danpeking24-May-17 23:33 
QuestionSql server: create table with column that support unique and multiple nulls Pin
w1424323-May-17 20:03
w1424323-May-17 20:03 
AnswerRe: Sql server: create table with column that support unique and multiple nulls Pin
Maciej Los23-May-17 20:27
mveMaciej Los23-May-17 20:27 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424323-May-17 20:45
w1424323-May-17 20:45 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming24-May-17 8:22
mveRichard Deeming24-May-17 8:22 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424324-May-17 17:32
w1424324-May-17 17:32 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming25-May-17 0:51
mveRichard Deeming25-May-17 0:51 
AnswerRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev24-May-17 3:15
professionalZurdoDev24-May-17 3:15 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming24-May-17 8:19
mveRichard Deeming24-May-17 8:19 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev24-May-17 8:24
professionalZurdoDev24-May-17 8:24 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424324-May-17 17:45
w1424324-May-17 17:45 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev25-May-17 0:49
professionalZurdoDev25-May-17 0:49 
QuestionDisplay data only from search parameters Pin
rattlerrFx23-May-17 7:16
rattlerrFx23-May-17 7:16 
QuestionRe: Display data only from search parameters Pin
CHill6023-May-17 10:52
mveCHill6023-May-17 10:52 
AnswerRe: Display data only from search parameters Pin
rattlerrFx23-May-17 13:21
rattlerrFx23-May-17 13:21 
GeneralRe: Display data only from search parameters Pin
CHill6024-May-17 1:06
mveCHill6024-May-17 1:06 
QuestionTeam Please help on the below request Pin
ganesh_naganna23-May-17 0:55
ganesh_naganna23-May-17 0:55 
AnswerRe: Team Please help on the below request Pin
Mycroft Holmes23-May-17 14:55
professionalMycroft Holmes23-May-17 14:55 
QuestionSQL for dynamic mappings Pin
Danpeking22-May-17 3:13
Danpeking22-May-17 3:13 
QuestionRe: SQL for dynamic mappings Pin
CHill6022-May-17 4:19
mveCHill6022-May-17 4:19 
AnswerRe: SQL for dynamic mappings Pin
Danpeking22-May-17 4:30
Danpeking22-May-17 4:30 
AnswerRe: SQL for dynamic mappings Pin
CHill6022-May-17 4:27
mveCHill6022-May-17 4:27 
Assuming you get the data sorted out then something like the following will work
SQL
SELECT * FROM
 (
	SELECT C.ClientID, ClientName, StatusDescription, 
	CASE WHEN SM.StatusID IS NOT NULL THEN 'Y' ELSE 'N' END AS Actual
	FROM @Clients C
	LEFT OUTER JOIN @Statuses S ON C.ClientID = S.ClientID
	LEFT OUTER JOIN @StatusMappings SM on SM.StatusID = S.StatusID
) qry
PIVOT 
(
	MAX(Actual) FOR StatusDescription in ([Draft Letter],[Awaiting Response],[Complete])
) pvt
WHERE ClientName = 'Barclays'
If you want to use it in an SSRS report then put the query into a Stored Procedure, passing the Client name or id as a parameter.

If the Status Descriptions are not standard or consistent (i.e. not the ones listed) then you will have to use some dynamic sql.

There are articles here on CodeProject on all the topics above
GeneralRe: SQL for dynamic mappings Pin
Danpeking22-May-17 4:36
Danpeking22-May-17 4:36 
GeneralRe: SQL for dynamic mappings Pin
CHill6022-May-17 4:39
mveCHill6022-May-17 4:39 
GeneralRe: SQL for dynamic mappings Pin
Danpeking22-May-17 5:46
Danpeking22-May-17 5:46 

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.