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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 building dynamic querys

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-04-04 : 08:04:15
i have 2 tables :
1) - icnludes few columns with rules of which data to use from tblData
for example : col1 has : substring(col3,3,7)
and so on.
and a table with an ID, which means the RULE id number.
2)-tblData ==> the table with the actuall data

how can i combine in 1 query or more that when a role choosed, it will build a new query based o nthe rules and run and get results from tblData?

Thanks in advance
Peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-04 : 08:10:40
Not clear what you want. Post table structures, Sample data and expected output.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-04-04 : 08:28:24
table1:
id col1 col2
1 substring(col3,3,5) substring(col1,1,5)
2 substring(col3,3,2) substring(col1,1,3)
3 substring(col3,3,3) substring(col1,1,1)

table2 contains
col1 "eeeeeeeeeeeeeeee" and col2 contains "9898198981"
(for all row - just for the example)

result :
when id=1 then eeeee98981
when id=2 then ee989
when id=3 then eee9

more clear?




Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-04 : 08:41:41
[code]-- Prepare sample data
DECLARE @Sample TABLE (ID INT, Start1 INT, Length1 INT, Start2 INT, Length2 INT)

INSERT @Sample
SELECT 1, 3, 5, 1, 5 UNION ALL
SELECT 2, 3, 2, 1, 3 UNION ALL
SELECT 3, 3, 3, 1, 1

DECLARE @Data TABLE (Col1 VARCHAR(20), Col2 VARCHAR(20))

INSERT @Data
SELECT 'eeeeeeeeeeeeeeee', '9898198981'

-- Show the expected output
SELECT SUBSTRING(d.Col1, s.Start1, s.Length1) + SUBSTRING(d.Col2, s.Start2, s.Length2)
FROM @Data AS d
INNER JOIN @Sample AS s ON s.ID = 2[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -