Hi Guys,
Thanks for all the help. I ended up trying Roji's approach and it works
great. Now, I just need to know how to group all the numbers into a group
called 'Numbers'.
Here's the stuff you'll need. BTW Roji, I owe you a beer ;).
Khurram
uSE PUBS
go
--Select * FROM titles
CREATE TABLE #Letters(Letter CHAR(1))
INSERT INTO #Letters VALUES('0')
INSERT INTO #Letters VALUES('1')
INSERT INTO #Letters VALUES('2')
INSERT INTO #Letters VALUES('3')
INSERT INTO #Letters VALUES('4')
INSERT INTO #Letters VALUES('5')
INSERT INTO #Letters VALUES('6')
INSERT INTO #Letters VALUES('7')
INSERT INTO #Letters VALUES('8')
INSERT INTO #Letters VALUES('9')
INSERT INTO #Letters VALUES('A')
INSERT INTO #Letters VALUES('B')
INSERT INTO #Letters VALUES('C')
INSERT INTO #Letters VALUES('D')
INSERT INTO #Letters VALUES('E')
INSERT INTO #Letters VALUES('F')
INSERT INTO #Letters VALUES('G')
INSERT INTO #Letters VALUES('H')
INSERT INTO #Letters VALUES('I')
INSERT INTO #Letters VALUES('J')
INSERT INTO #Letters VALUES('K')
INSERT INTO #Letters VALUES('L')
INSERT INTO #Letters VALUES('M')
INSERT INTO #Letters VALUES('N')
INSERT INTO #Letters VALUES('O')
INSERT INTO #Letters VALUES('P')
INSERT INTO #Letters VALUES('Q')
INSERT INTO #Letters VALUES('R')
INSERT INTO #Letters VALUES('S')
INSERT INTO #Letters VALUES('T')
INSERT INTO #Letters VALUES('U')
INSERT INTO #Letters VALUES('V')
INSERT INTO #Letters VALUES('W')
INSERT INTO #Letters VALUES('X')
INSERT INTO #Letters VALUES('Y')
INSERT INTO #Letters VALUES('Z')
SELECT L.Letter,
Min(CASE WHEN T.Title Is NULL Then 0 Else 1 End) As HasBook
FROM #Letters L
LEFT OUTER JOIN Titles T
ON L.Letter = LEFT(T.Title,1)
GROUP BY L.Letter
[quoted text, click to view] "Khurram Chaudhary" <chaudharykhurram@hotmail.com> wrote in message
news:uUaz35ZWEHA.2928@tk2msftngp13.phx.gbl...
> Hi,
>
> What I'm trying to do is have a stored procedure output single letters and
> numbers based on the results of a table. For example, let's say you have
the
> following:
>
> Book Title Intended
> Result
> Die Hard 2 D
> Three Pigs T
> Microsoft SQL M
> 1980 1
>
> However, not only do I want to get just the first letters of each Book
> Title, but I would like to have a 0 displayed if there are no instances of
> that letter/number and 1 if there is, shown as follows:
>
> A 0
> B 0
> C 0
> D 1
> and so on ...
>
> Finally, I would like group numbers together into a group called
'Numbers'.
> If there is one title that starts with 1 but the rest of the numbers are
0,
> the result should be that Numbers is 1. It should like something like
this:
>
> Numbers 1
> A 0
> B 0
> C 0
> D 1
> and so on ....
>
> Does anyone have any ideas? Thanks in advance.
>
> Khurram
>
>