all groups > sql server programming > november 2004 >
You're in the

sql server programming

group:

View in SQL


View in SQL Granville
11/14/2004 11:58:02 PM
sql server programming:
Good day

I have a table in SQL with the following columsn in it

Column A Clumn B
6000 4
6001 5
6002 4
6003 8
6004 6
7000 8
7001 7
7009 8
7010 4
8000 3
8019 2
8020 5

I want to create a view where I can add a Column C but I want the Column to
show the following

Column A Clumn B Column C
6000 4 6000
6001 5 6000
6002 4 6000
6003 8 6000
6004 6 6000
7000 8 7000
7001 7 7000
7009 8 7000
7010 4 7000
8000 3 8000
8019 2 8000
8020 5 8000


AS you can see, I'm trying to create one parent for the 6000, 7000 and 800
Ranges.

Any suggestions

Granville
Re: View in SQL patrickbrisbine NO[at]SPAM hotmail.com
11/15/2004 8:07:16 AM
If you don't have to many categories you could use a case statement:

SELECT ColumnA, ColumnB,
CASE
WHEN ColumnA BETWEEN 6000 AND 6999 THEN 6000
WHEN ColumnA BETWEEN 7000 AND 7999 THEN 7000
WHEN ColumnA BETWEEN 8000 AND 8999 THEN 8000
END AS "ColumnC"
FROM [TableName]


[quoted text, click to view]
Re: View in SQL Uri Dimant
11/15/2004 10:17:00 AM
Hi
CREATE TABLE Test
(
col INT ,
col1 AS LEFT(col,1)+'000'
)
go
insert into Test(col) VALUES (7008)

OR you can add the column within VIEW


CREATE VIEW My_View
AS
SELECT col,LEFT(col,1)+'000' as col1
FROM Test



[quoted text, click to view]

Re: View in SQL avnrao
11/15/2004 1:46:15 PM
Select ColumnA, ColumnB, (ColumnA/1000) * 1000

Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet

[quoted text, click to view]

AddThis Social Bookmark Button