Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:48:36+00:00 2026-05-26T18:48:36+00:00

I am working on defining a sql query for use in sql server compact

  • 0

I am working on defining a sql query for use in sql server compact edition 3.5 on a windows mobile handset. I am going to need to get back a result set from three tables.

I don’t exactly remember all the column names, as I’m asking this question at home, but here is a good example of the tables I’m dealing with.

Table 1: Customers
Table 2: PresoldOrders
Table 3: CustomerDetails

*

 ________________________________________
|                                        |
|--------------- Customers --------------|
|________________________________________|
|                                        |
| PK    int            CustomerNumber    |
|       varchar(125)   FirstName         |
|       varchar(125)   LastName          |
|       varchar(125)   Email             |
|       varchar(200)   Address1          |
|       varchar(200)   Address2          |
|       varchar(200)   City              |
|       varchar(2)     State             |
|       varchar(5)     Zip               |
|________________________________________|

*

 ________________________________________
|                                        |
|------------ CustomerDetails -----------|
|________________________________________|
|                                        |
| PK    int            CustomerDetailsId |
| FK    int            CustomerNumber    |
|       varchar(255)   FieldName         |
|       varchar(255)   FieldValue        |
|________________________________________|

*

 ________________________________________
|                                        |
|------------ PresoldOrders -------------|
|________________________________________|
|                                        |
| PK    int            PresoldOrderId    |
| FK    int            CustomerNumber    |
|       int            OrderNumber       |
|       int            RouteStopNumber   |
|       datetime       DeliveryDate      |
|       varchar(100)   Other1            |
|       varchar(100)   Other2            |
|________________________________________| 

Now, the query should return all records that exist in customers even if they don’t exist in ‘PresoldOrderHeaders’ table. This part of it is pretty easy, I plan to just use a left outer join. The second part of the query is a bit more complex.

Here is the query I’ve constructed so far.

SELECT c.CustomerNumber
       c.FirstName
       c.LastName
       c.Email
       c.Address1
       c.Address2
       c.City
       c.State
       c.Zip
       po.OrderNumber
       po.DeliveryDate
       po.Other1
       po.Other2
FROM Customer c
LEFT OUTER JOIN PresoldOrders po on c.CustomerNumber = po.CustomerNumber
ORDER BY po.RouteStopNumber; 

Tricky part is the CustomerDetails table. Here is an example of some data

 _________________________________________________________
|       |                 |              |                |
| PK    | CustomerNumber  | FieldName    | FieldValue     |
|-------|-----------------|--------------|----------------|
| 1     | 1               | A            | 125            |
|-------|-----------------|--------------|----------------|
| 2     | 1               | B            | 126            |
|-------|-----------------|--------------|----------------|
| 3     | 1               | C            | 127            |
|-------|-----------------|--------------|----------------|
| 4     | 2               | A            | 138            |
|-------|-----------------|--------------|----------------|
| 5     | 2               | B            | 140            |
|-------|-----------------|--------------|----------------|
| 6     | 2               | C            | 143            |
|-------|-----------------|--------------|----------------|
|_________________________________________________________|

For the information that I will be displaying in the Component One Flex Grid, the FieldName’s listed in the CustomerDetails table will be fixed.

Here is want I want to archive:

 _____________________________________________________________________________________________________________________
|                 |           |          |     |                     |                     |                          |
| CustomerNumber  | FirstName | LastName | ... | FieldName A's value | FieldName B's Value | FieldName C's Value      |
|-----------------|-----------|----------|-----|---------------------|---------------------|--------------------------|
| 1               | John      | Someone  | ... | 125                 | 126                 | 127                      |
|-----------------|-----------|----------|-----|---------------------|---------------------|--------------------------|
| 2               | Dan       | Other    | ... | 138                 | 140                 | 143                      |
|-----------------|-----------|----------|-----|---------------------|---------------------|--------------------------|
|_____________________________________________________________________________________________________________________|

Normally, I’d have column names for A, B, and C defined in the ‘CustomerDetails’ table; however, this table can’t be changed, so I must work with what I’ve been given. The requirements in the spec for my task is to have 15 plus columns to be displayed in a grid on a mobile device; not something I’d go for but those are the requirements.

Ok finally, the question:

Can one use sql to query a key value pairing table and have those key’s value’s displayed in columns like the above? This is the requirement I have and I’m thinking I’ll need to create one query with my join on presoldorders table and then get a list of all details for each customer in a list and iterate through and combine into data table in code on handheld.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:48:36+00:00Added an answer on May 26, 2026 at 6:48 pm

    If you know in advance all key values, you can pivot resultset. I’m not sure if sql server compact supports PIVOT, but you can do:
    select CustomerNumber,
    Max(Case when FieldName='A' then FieldValue end) as a_value,
    // the same for B, C, all keys.
    From CustomerDetails
    Group by CustomerNumber

    For simplicity I don’t join other tables, but I hope it gives you an idea how to turn rows into columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been working with a lot of TimeSpans recently, and have a need to get
We are working with a legacy database that uses SQL server uniqueidentifier columns for
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN
I'm working on a small project, and need to implement internationalization support somehow. I
My Case: I'm working on a system that will need to create various X12
I have working copy of war file which is working fine in windows.. Now
We are migrating ASP code that used ADO to connect to SQL Server 2000.
I am working on a bash script where I need to conditionally execute some
I'm defining a delete trigger, and I need to backup the row deleted but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.