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.
| 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 tblDatafor 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 datahow 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 advancePelegIsrael -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 AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-04-04 : 08:28:24
|
| table1:id col1 col21 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 eeeee98981when id=2 then ee989when id=3 then eee9more clear?Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 08:41:41
|
| [code]-- Prepare sample dataDECLARE @Sample TABLE (ID INT, Start1 INT, Length1 INT, Start2 INT, Length2 INT)INSERT @SampleSELECT 1, 3, 5, 1, 5 UNION ALL SELECT 2, 3, 2, 1, 3 UNION ALLSELECT 3, 3, 3, 1, 1DECLARE @Data TABLE (Col1 VARCHAR(20), Col2 VARCHAR(20))INSERT @DataSELECT 'eeeeeeeeeeeeeeee', '9898198981'-- Show the expected outputSELECT SUBSTRING(d.Col1, s.Start1, s.Length1) + SUBSTRING(d.Col2, s.Start2, s.Length2)FROM @Data AS dINNER JOIN @Sample AS s ON s.ID = 2[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|