madanthrax
IS-IT--Management
Hi,
I have access to a read only view from the printing dept DB in our organisation. We all use MS SQL 2005. The DB is poorly designed and is out of my control.
Through a series of views of views I piece the data together and use it on our website as we want to display it.
The pages display book details. There are two series of books, guides and requirements. The series information is is next to the title (SeriesInfo in the DB). There is an old and a new form of the series pattern, for example: GS-R-2, GS-G-3, and SSR4, SSG2. The R or G at character 4 in the first pair and the R or G at character 3 in the second pair denote Requirement or Guide.
I want to create a view that parses the 'SeriesInfo' column string to look for these characters in these positions and depending on the result put a 1 or 2 value dynamically in an extra column called Category.
I have no real idea what I am doing in SQL code but I have put this together from info gathered from the web:
Naturally I can't get this to work. I am not even sure if this is the right way to go about it.
Any help would be gratefully appreciated,
regards,
Anthony.
I have access to a read only view from the printing dept DB in our organisation. We all use MS SQL 2005. The DB is poorly designed and is out of my control.
Through a series of views of views I piece the data together and use it on our website as we want to display it.
The pages display book details. There are two series of books, guides and requirements. The series information is is next to the title (SeriesInfo in the DB). There is an old and a new form of the series pattern, for example: GS-R-2, GS-G-3, and SSR4, SSG2. The R or G at character 4 in the first pair and the R or G at character 3 in the second pair denote Requirement or Guide.
I want to create a view that parses the 'SeriesInfo' column string to look for these characters in these positions and depending on the result put a 1 or 2 value dynamically in an extra column called Category.
I have no real idea what I am doing in SQL code but I have put this together from info gathered from the web:
Code:
USE [Documents]
GO
/****** Object: View [dbo].[vw_WebDocs5] Script Date: 09/23/2010 17:31:07 ******/
SET ANSI_NULLS ON
GO
CREATE VIEW [dbo].[vw_WebDocs5]
(PubId, Title, Language, ElectronicFile, FileSize, SeriesInfo, Released,
CASE WHEN SUBSTRING(SeriesInfo, 4, 1) = 'R' THEN '1' AS Category
WHEN SUBSTRING(SeriesInfo, 3, 1) = 'R' THEN '1' AS Category
ELSE '2' AS Category
END )
FROM dbo.vw_WebDocs4
Naturally I can't get this to work. I am not even sure if this is the right way to go about it.
Any help would be gratefully appreciated,
regards,
Anthony.
[sub]"Nothing is impossible until proven otherwise"[/sub]