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 |
|
vikky
Yak Posting Veteran
54 Posts |
Posted - 2010-03-30 : 08:12:26
|
| declare @table table(id int,contents varchar(max),val varchar(max))insert into @table select 1,'a b c d','1 2 3 4' union all select 1,'a b d','1 2 4' union all select 2,'a b c d','1 2 3 4'select * from @table output:1 a 11 b 21 c 31 d 41 a 11 b 21 d 32 a 12 b 22 c 32 d 4thanks in advance. |
|
|
vikky
Yak Posting Veteran
54 Posts |
Posted - 2010-03-30 : 08:23:44
|
| hi experts,please work on this. any help on this solved my problem other wise ---.thanks in advance. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-03-30 : 09:26:44
|
| What are we supposed to work on? The extra bad design of the database?http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-03-30 : 09:45:00
|
| I think she's asking for a select query that will give the supplied output from the supplied table.There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-03-30 : 09:48:58
|
| Ah. Then my advise is to follow the HOW TO ASK link in my signature.We seem to be missing the logic that defines how to get the output...http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-30 : 09:51:21
|
How do you know person is SHE Vaibhav T |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-30 : 10:18:15
|
Below is the solution -CREATE table #table (id int,contents varchar(max),val varchar(max))insert into #table select 1,'a b c d','1 2 3 4' union all select 1,'a b d','1 2 4' union all select 2,'a b c d','1 2 3 4'DECLARE @tbl AS TABLE( id int, Contents Varchar(MAX), Val Varchar(MAX) )DECLARE @id int, @Contents AS VARCHAR(MAX), @Val AS VARCHAR(MAX)DECLARE cur CURSORFOR SELECT ID, Contents, val FROM #tableOPEN curFETCH NEXT FROM cur INTO @id , @Contents , @Val WHILE @@FETCH_STATUS = 0BEGIN INSERT INTO @tbl SELECT @id, a.strdata, b.strdata FROM ( SELECT strdata , ROW_NUMBER()OVER (ORDER BY strData) Seq FROM SplitText(@Contents, ' ') ) a INNER JOIN ( SELECT strdata , ROW_NUMBER()OVER (ORDER BY strData) Seq FROM SplitText(@Val, ' ') ) b ON a.seq = b.seq FETCH NEXT FROM cur INTO @id , @Contents , @Val END ClOSE curDEALLOCATE curSELECT * FROM @tbl Vaibhav T |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-30 : 10:22:07
|
Scrip for the Function SplitText -CREATE FUNCTION [dbo].[SplitText] (@list ntext, @delimiter nchar(1) = N',') RETURNS @tbl TABLE (--listpos int IDENTITY(1, 1) NOT NULL, --nstr nvarchar(2000) , strData varchar(4000)) AS BEGIN DECLARE @pos int, @textpos int, @chunklen smallint, @tmpstr nvarchar(4000), @leftover nvarchar(4000), @tmpval nvarchar(4000) SET @textpos = 1 SET @leftover = '' WHILE @textpos <= datalength(@list) / 2 BEGIN SET @chunklen = 4000 - datalength(@leftover) / 2 SET @tmpstr = @leftover + substring(@list, @textpos, @chunklen) SET @textpos = @textpos + @chunklen SET @pos = charindex(@delimiter, @tmpstr) WHILE @pos > 0 BEGIN SET @tmpval = ltrim(rtrim(left(@tmpstr, @pos - 1))) --INSERT @tbl (str, nstr) VALUES(@tmpval, @tmpval) INSERT @tbl (strData) VALUES( @tmpval) SET @tmpstr = substring(@tmpstr, @pos + 1, len(@tmpstr)) SET @pos = charindex(@delimiter, @tmpstr) END SET @leftover = @tmpstr END --INSERT @tbl(str, nstr) VALUES (ltrim(rtrim(@leftover)), ltrim(rtrim(@leftover))) INSERT @tbl(strData) VALUES (ltrim(rtrim(@leftover))) RETURN END Vaibhav T |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-03-30 : 10:27:45
|
quote: Originally posted by vaibhavktiwari83 How do you know person is SHE 
Because Vikky is a girl's name. There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-30 : 10:30:34
|
quote: Originally posted by DBA in the making
quote: Originally posted by vaibhavktiwari83 How do you know person is SHE 
Because Vikky is a girl's name. There are 10 types of people in the world, those that understand binary, and those that don't.
Go to his profile his name is vikrant and in india vikky is name of boy not a girl Vaibhav T |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-03-30 : 10:56:04
|
[b]WARNING: The following post is intended to be read only by those with a sense of humor.[/bquote: Originally posted by vaibhavktiwari83Go to his profile his name is vikrant and in india vikky is name of boy not a girl 
It's not my fault you guys have funny sounding names. It's hard enough analysing the question he posted and working out what he's asking, let alone analysing 26 letters of the alphabet and picking a name out of it. :)There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
|
|
|
|
|