Hi all can help for select data in Table that have data below:
ID Level Code
1 1 1-0-00-00-000
2 2 1-1-00-00-000
3 3 1-1-01-00-000
4 4 1-1-01-01-000
5 5 1-1-01-01-001
6 5 1-1-01-01-002
7 5 1-1-01-01-003
8 2 1-2-00-00-000
9 3 1-2-01-00-000
10 4 1-2-01-01-000
In this table i want select data that show data below:
ID Level Code
1 1 1
2 2 1-1
3 3 1-1-01
4 4 1-1-01-01
5 5 1-1-01-01-001
6 5 1-1-01-01-002
7 5 1-1-01-01-003
8 2 1-2
9 3 1-2-01
10 4 1-2-01-01
i try to select but can not and i want take
this query show on treeview
i don't want show code have along code only
show code by Level
if Level 1 it show only 1 and Level2 only show 1-1
and other Level it show by symbol(-)
thank Advance
Loading
Sanjay ChauhanPosted Aug 28, 2009, 3:25 AM
try this query to get the output
CREATE TABLE #Temp1(ID INT,Lavel INT,Code VARCHAR(50))
INSERT [#Temp1] (
[ID],
[Lavel],
[Code]
)
SELECT ID,Lavel, REPLACE(Code,'-000','') FROM TestingTable
UPDATE #Temp1 SET [Code]=REPLACE(Code,'-00','') WHERE code not LIKE '%-00_'
UPDATE #Temp1 SET [Code]=REPLACE(Code,'-0','') WHERE code not LIKE '%-0_' AND code not LIKE '%-00_'
SELECT * FROM [#Temp1]
DROP TABLE [#Temp1]
Manath PathanaPosted Aug 28, 2009, 9:29 PM
this data.