Advertisement

11.08.2007 at 08:15AM PST, ID: 22947737
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Crosstab Query In Sybase

Asked by grav0005 in Sybase Database, SQL Query Syntax

Tags: , ,

Hi everybody,

I'm writing a stored proc in Sybase for a crosstab report in Crystal 10 and I don't know exactly how to get what I want.  The report contains a count of Nationalities by Canadian Region.

I can retrieve all the Nationalities along with their associated region, but I can't convert that to a crosstab format that has counts for each region:

Nationality      Port of Arrival            
      Altantic      Prairie      Greater Toronto Area ...
Albania      3      7      16
Ghana      1      4      0
Morrocco      25      2      10
Zimbabwe      1      31      7

Here is what I have so far.  It results in the following output:

citizenship            region_cd      region                                          region_1      region_2      region_3      region_4      region_5      region_6
Abu Dhabi            10008261      British Columbia/yukon Region      0                  0                  1                  0                  0                  0
Armenia                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Austria                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Azerbaijan            10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Azerbaijan            10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Azerbaijan            10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Azerbaijan            10008264      Quebec Region                              0                  0                  0                  0                  0                  1
Azerbaijan            10008264      Quebec Region                              0                  0                  0                  0                  0                  1
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahamas Islands      10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahrain                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahrain                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahrain                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahrain                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0
Bahrain                  10008260      Atlantic Region                              0                  1                  0                  0                  0                  0

Here is my query so far:

create table #region_count
(
       citizenship  varchar(50) NOT NULL
      ,region_cd    int         NOT NULL    
      ,region       varchar(50) NOT NULL
      ,region_1     int         NULL
      ,region_2     int         NULL
      ,region_3     int         NULL
      ,region_4     int         NULL
      ,region_5     int         NULL
      ,region_6     int         NULL
)

insert  #region_count
    select "citizenship" = isnull (( select case when @language_cd  = 'fr'
                                            then french_desc
                                            else english_desc
                                         end
                                      from    vcode_value cv
                                      where   cv.code_value_id = cit.citizenship_country_cd ), '')
 
                                 
        ,dr.p_code_value_id
       
        ,"region" =  isnull ( case  when @language_cd  = 'fr'
                                    then dr.p_french_desc
                                    else dr.p_english_desc
                              end, '')  
        ,"region_1" = (case dr.p_code_value_id when 10006446 then 1 else 0 end)
        ,"region_2" = (case dr.p_code_value_id when 10008260 then 1 else 0 end)
        ,"region_3" = (case dr.p_code_value_id when 10008261 then 1 else 0 end)
        ,"region_4" = (case dr.p_code_value_id when 10008262 then 1 else 0 end)
        ,"region_5" = (case dr.p_code_value_id when 10008263 then 1 else 0 end)
        ,"region_6" = (case dr.p_code_value_id when 10008264 then 1 else 0 end)                                                                          
from vssi                       s
    ,vclient                    cl
      ...
   
where   ...

       

order by ...
 

/****************************************************************************/
/*  RESULTS                                                                 */
/****************************************************************************/
set nocount off

select *
from #region_count
order by citizenship
        ,region

Thanks a lot,

Rob


Start Free Trial
[+][-]11.08.2007 at 09:03AM PST, ID: 20242924

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.08.2007 at 10:15AM PST, ID: 20243551

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.08.2007 at 10:52AM PST, ID: 20243894

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.08.2007 at 12:13PM PST, ID: 20244674

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.08.2007 at 01:46PM PST, ID: 20245591

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.13.2007 at 11:45AM PST, ID: 20274392

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Sybase Database, SQL Query Syntax
Tags: sybase, crosstab, query
Sign Up Now!
Solution Provided By: grav0005
Participating Experts: 2
Solution Grade: B
 
 
[+][-]01.21.2008 at 01:16PM PST, ID: 20709757

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628