Click here to Skip to main content
15,398,348 members
Home / Discussions / Database
   

Database

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 3:10
cofounderChris Maunder16-Jul-09 3:10 
PinnedHow to get an answer to your question PinPopular
Chris Maunder10-Nov-05 16:30
cofounderChris Maunder10-Nov-05 16:30 
QuestionReplacing back-end MS-ACCESS with SQL SERVER Pin
Member 142165877-Aug-22 4:00
MemberMember 142165877-Aug-22 4:00 
AnswerRe: Repacing back-end MS-ACCESS with SQL SERVER Pin
Mycroft Holmes7-Aug-22 12:44
professionalMycroft Holmes7-Aug-22 12:44 
GeneralRe: Repacing back-end MS-ACCESS with SQL SERVER Pin
Member 142165878-Aug-22 5:42
MemberMember 142165878-Aug-22 5:42 
AnswerRe: Repacing back-end MS-ACCESS with SQL SERVER Pin
Richard Deeming7-Aug-22 21:50
mveRichard Deeming7-Aug-22 21:50 
GeneralRe: Replacing back-end MS-ACCESS with SQL SERVER Pin
Member 142165878hrs 5mins ago
MemberMember 142165878hrs 5mins ago 
GeneralRe: Replacing back-end MS-ACCESS with SQL SERVER Pin
Craig Robbins6hrs 19mins ago
MemberCraig Robbins6hrs 19mins ago 
AnswerRe: Replacing back-end MS-ACCESS with SQL SERVER Pin
CHill606hrs 12mins ago
mveCHill606hrs 12mins ago 
QuestionHow would you... (synchronization between 2 databases) Pin
Joan M6-Aug-22 7:18
professionalJoan M6-Aug-22 7:18 
AnswerRe: How would you... (synchronization between 2 databases) Pin
Gerry Schmitz6-Aug-22 8:06
mveGerry Schmitz6-Aug-22 8:06 
GeneralRe: How would you... (synchronization between 2 databases) Pin
Joan M6-Aug-22 12:08
professionalJoan M6-Aug-22 12:08 
AnswerRe: How would you... (synchronization between 2 databases) Pin
Mycroft Holmes6-Aug-22 12:48
professionalMycroft Holmes6-Aug-22 12:48 
Questionsql query problem Pin
pitwi27-Jul-22 23:06
Memberpitwi27-Jul-22 23:06 
AnswerRe: sql query problem Pin
Richard Deeming27-Jul-22 23:54
mveRichard Deeming27-Jul-22 23:54 
GeneralRe: sql query problem Pin
jsc426hrs 52mins ago
professionaljsc426hrs 52mins ago 
GeneralRe: sql query problem Pin
Richard Deeming6hrs 46mins ago
mveRichard Deeming6hrs 46mins ago 
Question.sql script in c# Pin
Member 1373522830-Jun-22 2:15
MemberMember 1373522830-Jun-22 2:15 
AnswerRe: .sql script in c# Pin
Dave Kreskowiak30-Jun-22 3:59
mveDave Kreskowiak30-Jun-22 3:59 
QuestionPivot works, but spread column values not as expected Pin
#realJSOP19-Jun-22 1:58
mva#realJSOP19-Jun-22 1:58 
AnswerRe: Pivot works, but spread column values not as expected Pin
Richard Deeming19-Jun-22 21:52
mveRichard Deeming19-Jun-22 21:52 
GeneralRe: Pivot works, but spread column values not as expected Pin
#realJSOP19-Jun-22 22:20
mva#realJSOP19-Jun-22 22:20 
GeneralRe: Pivot works, but spread column values not as expected Pin
Richard Deeming19-Jun-22 22:36
mveRichard Deeming19-Jun-22 22:36 
Maybe something like this?
SQL
WITH cte As
(
    SELECT
        UserId,
        VehId,
        VehImage,
        ROW_NUMBER() OVER (PARTITION BY UserId, VehId ORDER BY Id) As RN
    FROM
        @images
)
SELECT
    UserId,
    VehId,
    [1] As Image1,
    [2] As Image2,
    [3] As Image3,
    [4] As Image4,
    [5] As Image5,
    [6] As Image6,
    [7] As Image7,
    [8] As Image8,
    [9] As Image9,
    [10] As Image10
FROM
    cte As SourceTable
    PIVOT
    (
        Max(VehImage)
        FOR RN IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10])
    ) As PivotTable
;
Or without the pivot:
SQL
WITH cte As
(
    SELECT
        UserId,
        VehId,
        VehImage,
        ROW_NUMBER() OVER (PARTITION BY UserId, VehId ORDER BY Id) As RN
    FROM
        @images
)
SELECT
    UserId,
    VehId,
    MAX(CASE RN WHEN 1 THEN VehImage END) As Image1,
    MAX(CASE RN WHEN 2 THEN VehImage END) As Image2,
    MAX(CASE RN WHEN 3 THEN VehImage END) As Image3,
    MAX(CASE RN WHEN 4 THEN VehImage END) As Image4,
    MAX(CASE RN WHEN 5 THEN VehImage END) As Image5,
    MAX(CASE RN WHEN 6 THEN VehImage END) As Image6,
    MAX(CASE RN WHEN 7 THEN VehImage END) As Image7,
    MAX(CASE RN WHEN 8 THEN VehImage END) As Image8,
    MAX(CASE RN WHEN 9 THEN VehImage END) As Image9,
    MAX(CASE RN WHEN 10 THEN VehImage END) As Image10
FROM
    cte As SourceTable
GROUP BY
    UserId,
    VehId
;




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Pivot works, but spread column values not as expected Pin
#realJSOP19-Jun-22 23:19
mva#realJSOP19-Jun-22 23:19 
QuestionDatabase design for a project Pin
Gopika Ravikumar16-Jun-22 6:35
MemberGopika Ravikumar16-Jun-22 6:35 

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.