473,396 Members | 2,108 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,396 software developers and data experts.

Mssql

1
I have to copy text field from one record to another on the same table.

Can you help me?
Aug 1 '07 #1
2 820
mwasif
802 Expert 512MB
Moved to MS SQL forum.
Aug 1 '07 #2
I have to copy text field from one record to another on the same table.

Can you help me?
I dont know if this is the best way, but it works for me. I use a subquery in the FROM statement.

Expand|Select|Wrap|Line Numbers
  1. --Create our test table
  2. Create table table1
  3. (ID int, TextField varchar(10))
  4.  
  5. --Insert a few test rows with a key and a text data field
  6. Insert into table1
  7. Select 1, 'Test 1'
  8. Union All
  9. Select 2, 'Test 2'
  10. Union All
  11. Select 3, 'Test 3'
  12. Union All
  13. Select 4, 'Test 4'
  14.  
  15. --Display our table 
  16. Select * From table1
  17.  
  18.  
  19. /*
  20. Results
  21. ID          TextField
  22. ----------- ----------
  23. 1           Test 1
  24. 2           Test 2
  25. 3           Test 3
  26. 4           Test 4
  27.  
  28. (4 row(s) affected)
  29. */
  30.  
  31. (4 row(s) affected)
  32.  
  33. --Update the contents of record 3 with the text data from record 1
  34. Update table1
  35. Set TextField = A.TextField
  36. From (Select * From table1 Where ID = 1) A
  37. Where table1.ID = 3
  38.  
  39. --Display our table again with the new updated record 3
  40. Select * From table1
  41.  
  42. /*Results
  43. ID          TextField
  44. ----------- ----------
  45. 1           Test 1
  46. 2           Test 2
  47. 3           Test 1
  48. 4           Test 4
  49.  
  50. (4 row(s) affected)
  51. */
  52.  
Aug 1 '07 #3

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

Similar topics

11
by: badz | last post by:
Hi frenz Lately I try to use MSSQL and PHP , the problem arise when PHP try to read MSSQL field with 'image' data type, header("Content-type: image/jpeg"); // act as a jpg file to browser I...
7
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that...
1
by: JackTorrance | last post by:
Hi i have a problem with IIS6 and MSSQL and i hope that someone can help me. this is the configuration: Windows 2003 IIS6 MSSQL 7.0 Standard Edition ADO 2.5
14
by: Kukurydz | last post by:
I've got such problem: My database is stored on MSSQL Server. I have to write reports for it in MSAccess. I've got a problem with creating a query which will select records from MSSQL table with...
3
by: gharmel | last post by:
I'm trying to get some clues on why I get (much) slower responses from my PHP applications when dealing with a remote sql server as opposed to a local sql server. Here's my situation: Server...
11
by: ralphie | last post by:
hi all since nearly 2 days i fight with mssql and utf-8 as i need to store and retrieve arabic characters. i tried the com approach ...
0
by: DariuszK | last post by:
I am greeting I would like to consult the better solution(with security consideration) to the access is for MSSQL(2005) from ASP(Classic) in the system of the intranet. a) SQL mixed mode and...
8
by: php-taz | last post by:
I built a PHP website on Windows 2000 (using IIS) that connects to a SQL Server 2000 database using the mssql functions. I migrated the website and the database onto a Windows 2003 machine, and...
0
by: Derftics | last post by:
Hi Guys, Is there anyone who have tried installing MSSQL 2000 and MSSQL 2005 servers in one desktop computer? I have tried using MSDE and successfully install the MSSQL 2000 server but when I...
14
by: guswebb | last post by:
Hi. I'm a newbie to PHP and am having a few problems as follows... I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.