| Author |
Topic |
|
crishna
Starting Member
5 Posts |
Posted - 2008-10-29 : 15:06:18
|
| Hi,I need to write a queryAttached is the Image wich gives look of how my data looks now and what I need it look like with the queryCould you please help me with a query?Row Column LabelText TextBoxLabelText CheckBoxText FormCellTypeF7A8AE42 9C790FB2 Command and Display LabelF7A8AE42 B34B7D87 Command and Display LabelF7A8AE42 FFFFFFFFFF Check Engine Text FieldEDE01A0E 9C790FB2 Job Name TextFieldEDE01A0E B34B7D87 Job Name TextFieldEDE01A0E GGGGGGG Command labelDAC812FC 9C790FB2 Job Number TextFieldDAC812FC B34B7D87 Job Number TextFieldDAC812FC 8AF95DDC Job Number TextField Desired Result Row Column LabelText TextBoxLabelText CheckBoxText FormCellTypeF7A8AE42 9C790FB2 Command and Display LabelF7A8AE42 FFFFFFFF Check Engine Text FieldEDE01A0E 9C790FB2 Job Name TextFieldEDE01A0E GGGGGGG Command labelDAC812FC 9C790FB2 Job Number TextFieldCould any help me in writing query for above.Thanks |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-29 : 15:08:48
|
| http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113262&SearchTerms=remove,duplicate |
 |
|
|
crishna
Starting Member
5 Posts |
Posted - 2008-10-29 : 15:19:47
|
| Thanks for the reply,I looked at the post and I did use a similar query using Group By which return me the result, but it doesnt retunr me the first two columns I need.I am trying to retreive even the corresponding RowId and ColumnId also. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-29 : 15:21:28
|
Maybe it's not a bad idea to show your query so far...Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-29 : 18:05:25
|
[code]DECLARE @Sample TABLE ( Row CHAR(8), [Column] VARCHAR(10), LabelText VARCHAR(20), TextBoxLabelText VARCHAR(20), CheckBoxText VARCHAR(20), FormCellType VARCHAR(9) )INSERT @SampleSELECT 'F7A8AE42', '9C790FB2', 'Command and Display', NULL, NULL, 'Label' UNION ALLSELECT 'F7A8AE42', 'B34B7D87', 'Command and Display', NULL, NULL, 'Label' UNION ALLSELECT 'F7A8AE42', 'FFFFFFFFFF', NULL, 'Check Engine', NULL, 'TextField' UNION ALLSELECT 'EDE01A0E', '9C790FB2', NULL, 'Job Name', NULL, 'TextField' UNION ALLSELECT 'EDE01A0E', 'B34B7D87', NULL, 'Job Name', NULL, 'TextField' UNION ALLSELECT 'EDE01A0E', 'GGGGGGG', 'Command', NULL, NULL, 'Label' UNION ALLSELECT 'DAC812FC', '9C790FB2', NULL, 'Job Number', NULL, 'TextField' UNION ALLSELECT 'DAC812FC', 'B34B7D87', NULL, 'Job Number', NULL, 'TextField' UNION ALLSELECT 'DAC812FC', '8AF95DDC', NULL, 'Job Number', NULL, 'TextField'SELECT Row, [Column], LabelText, TextBoxLabelText, CheckBoxText, FormCellTypeFROM ( SELECT Row, [Column], LabelText, TextBoxLabelText, CheckBoxText, FormCellType, ROW_NUMBER() OVER (PARTITION BY Row, LabelText, TextBoxLabelText, CheckBoxText, FormCellType ORDER BY Row) AS recID FROM @Sample ) AS dWHERE recID = 1ORDER BY Row DESC, [Column]DELETE fFROM ( SELECT ROW_NUMBER() OVER (PARTITION BY Row, LabelText, TextBoxLabelText, CheckBoxText, FormCellType ORDER BY Row) AS recID FROM @Sample ) AS fWHERE recID > 1SELECT Row, [Column], LabelText, TextBoxLabelText, CheckBoxText, FormCellTypeFROM @SampleORDER BY Row DESC, [Column][/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|