Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE Select in SQL Query

Author  Topic 

velnias2010
Posting Yak Master

125 Posts

Posted - 2010-07-28 : 05:42:01
Hey I have the following query which works fine

quote:
SELECT ROW_NUMBER() OVER(ORDER BY LEFT(UPPER(xml_index.value_string), 1)) as rownumber,alias_pagename, [content].content_title, LEFT(UPPER(xml_index.value_string), 1) AS Letter, [content].content_id, 2 AS col,value_string
FROM [content] INNER JOIN
xml_index ON [content].content_id = xml_index.content_id AND [content].content_language = xml_index.content_language INNER JOIN url_alias_tbl AS Q ON [content].content_id = Q.content_id
WHERE ([content].folder_id = @folderId) AND ([content].inherit_xml_from = @folderId) AND ([content].published = 1) AND ([content].content_type = 1) AND
([content].xml_config_id = @configId) AND ([content].content_status LIKE 'A') AND (xml_index.xpath LIKE '/root/Surname')
ORDER BY letter,value_string


I want to add the following bit to it

quote:
SELECT value_string
FROM xml_index AS p
WHERE (O.content_id = content_id) AND (xpath = '/root/Category')) AS Category

So that in the end in my select I can add

Case category WHEN 'Managing Partner' THEN 'Partner' WHEN 'Chairman' THEN 'Partner' ELSE category End as category

But not sure how to get this done cheers

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-28 : 05:56:01
please post schema for xml_index table.
Go to Top of Page

velnias2010
Posting Yak Master

125 Posts

Posted - 2010-07-28 : 05:58:54
Like this

CREATE TABLE [dbo].[xml_index](
[xml_config_id] [int] NOT NULL,
[xpath] [nvarchar](512) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[xpath_exp] [nvarchar](512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[content_id] [int] NOT NULL,
[content_language] [int] NOT NULL,
[folder_id] [int] NOT NULL,
[value_number] [float] NULL,
[value_string] [nvarchar](2000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[value_date] [datetime] NULL,
[value_bool] [int] NULL
) ON [PRIMARY]
Go to Top of Page
   

- Advertisement -