473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL Server

can any one help me to solve the following problem.
i have a table name "detail" and field contains name,age,remarks1,remarks2

and data content

name age remark1 remark2
bishnu 22 aaa ssss
priya 27 ff gg
gopal 12 tt ww

now i want to generate a new table name "complete" which generate the following table as from table name "detail"

name age remark
bishnu 22 aaa
bishnu 22 ssss
priya 27 ff
priya 27 gg
gopal 12 tt
gopal 12 ww

please tell me the sql coding for solving this problem.plz help
Nov 12 '07 #1
2 903
debasisdas
8,127 Expert 4TB
As you have posted a question in the SQL Server Articles section it is being moved to SQL Server Forum.
Nov 12 '07 #2
Jim Doherty
897 Expert 512MB
can any one help me to solve the following problem.
i have a table name "detail" and field contains name,age,remarks1,remarks2

and data content

name age remark1 remark2
bishnu 22 aaa ssss
priya 27 ff gg
gopal 12 tt ww

now i want to generate a new table name "complete" which generate the following table as from table name "detail"

name age remark
bishnu 22 aaa
bishnu 22 ssss
priya 27 ff
priya 27 gg
gopal 12 tt
gopal 12 ww

please tell me the sql coding for solving this problem.plz help

If you merely want to bring in remarks2 column so that it becomes remarks1 column then a SELECT INTO statement will automatically create a table for you called 'content' defined according to the UNION of Two SELECT statements of data retrieved from the source table 'detail' and in so doing inherit the datatypes of the source table in the process as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     TOP 100 PERCENT name, age, remark1
  3. INTO            content
  4. FROM         (SELECT     name, age, remark1
  5.                      FROM         dbo.detail
  6.                      UNION ALL
  7.                      SELECT     name, age, remark2
  8.                      FROM         dbo.detail) DERIVEDTABLE
  9. ORDER BY name
  10.  

You can run this SQL either in query analyser of in the 'View' designer window (although in the latter whilst you will be prompted by the designer that it does not support the SQL statement type in a view it will still run it as valid syntax and thus create your table and populate it accordingly)

if your strict need is to have the field name of 'Remark' as a replacement in effect for the Remark1 field in the newly created table then you can alias the name as bold highlighted in the following repeat of the above SQL at which point the new table 'content' will reflect that field name.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     TOP 100 PERCENT name, age, remark1 AS Remark
  3. INTO            content
  4. FROM         (SELECT     name, age, remark1
  5.                      FROM         dbo.detail
  6.                      UNION ALL
  7.                      SELECT     name, age, remark2
  8.                      FROM         dbo.detail) DERIVEDTABLE
  9. ORDER BY name
  10.  
Research the UNION operator in SQL to understand how data is treated using this particular method. In your specific example data case there is no duplication of data, but in a real data sense if there were duplications caused by the UNION then removing the ALL word (highlighted above) would cause the dataset to be created and remove any duplications automatically.

The UNION operator allows you to combine the results of two or more SELECT statements into a single result set. The result sets combined using UNION must all have the same structure. They must have the same number of columns, and the corresponding result set columns must have compatible data types.

Hope this helps you.

Regards

Jim :)
Nov 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
9
by: Grim Reaper | last post by:
My work let me put SQL Server 7.0 Enterprise Edition on my laptop. I have never setup a server from the beginning, so I am a little new at creating server groups. Alright, I am trying to create...
0
by: Chris Halcrow | last post by:
Hi I've spent ALL DAY trying to re-install SQL Server 2000 on Windows XP. I continually get the error 'cannot configure server' just at the end of the installation. I've tried the following: ...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.