Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Update Query
Hi all,

I need ur help.

I have data like this.


Table name            :                mytable.

------------------------------------------------------------
sno          Sem                mark1                 mark2
-----------------------------------------------------------
1              1                      71                      0
2              1                      85                      0
3              1                      80                      0
4              2                      10                      0
5              2                      20                     0
6              2                      30                      0
---------------------------------------------------------------

I want an update query to update all mark2 field have the same as mark1
field where SEM  = 1

that is , The output after the updation is like :

------------------------------------------------------------
sno          Sem                mark1                 mark2
-----------------------------------------------------------
1              1                      71                      71
2              1                      85                      85
3              1                      80                      80
4              2                      10                      0
5              2                      20                     0
6              2                      30                      0
---------------------------------------------------------------

Please give me the update Query.


Thanks in Advance.

with warm Regards,
Thangaraju


Report this thread to moderator Post Follow-up to this message
Old Post
Goldking
10-29-06 12:14 AM


Re: Update Query
try with:

Update mytable
set mark2 = mark1
from mytable
where mytable.SEM = 1


Its not ANSI syntax but it works on sql server and it should be pretty
obvious how it works...

MC

"Goldking" <gold.study@gmail.com> wrote in message
news:1162018081.367486.23820@b28g2000cwb.googlegroups.com...
> Hi all,
>
> I need ur help.
>
> I have data like this.
>
>
> Table name            :                mytable.
>
> ------------------------------------------------------------
> sno          Sem                mark1                 mark2
> -----------------------------------------------------------
> 1              1                      71                      0
> 2              1                      85                      0
> 3              1                      80                      0
> 4              2                      10                      0
> 5              2                      20                     0
> 6              2                      30                      0
> ---------------------------------------------------------------
>
> I want an update query to update all mark2 field have the same as mark1
> field where SEM  = 1
>
> that is , The output after the updation is like :
>
> ------------------------------------------------------------
> sno          Sem                mark1                 mark2
> -----------------------------------------------------------
> 1              1                      71                      71
> 2              1                      85                      85
> 3              1                      80                      80
> 4              2                      10                      0
> 5              2                      20                     0
> 6              2                      30                      0
> ---------------------------------------------------------------
>
> Please give me the update Query.
>
>
> Thanks in Advance.
>
> with warm Regards,
> Thangaraju
>



Report this thread to moderator Post Follow-up to this message
Old Post
MC
10-29-06 12:14 AM


Re: Update Query
MC  wrote:
> try with:
>
> Update mytable
> set mark2 = mark1
> from mytable
> where mytable.SEM = 1
>
>
> Its not ANSI syntax ...
>


But it would be if you remove the FROM clause, which is completely
unnecessary in this case.

Goldking,
Please do not multi-post.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--


Report this thread to moderator Post Follow-up to this message
Old Post
David Portas
10-29-06 12:14 AM


Re: Update Query
I agree (offcourse :)), the point was to make it obvious how to expand the
update (some join possibly and similar)

MC

"David Portas" < REMOVE_BEFORE_REPLYI
NG_dportas@acm.org> wrote in message
news:1162019932.983071.281450@k70g2000cwa.googlegroups.com...
> MC wrote: 
>
>
> But it would be if you remove the FROM clause, which is completely
> unnecessary in this case.
>
> Goldking,
> Please do not multi-post.
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>



Report this thread to moderator Post Follow-up to this message
Old Post
MC
10-31-06 05:15 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 09:20 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006