|
|
The most simple question ever |
|
Author |
Message |
MalcolmFowler
|
Posted: Sat Apr 07 19:26:46 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
I know absolutaley nothing of SQL scripting and need what is probably
the most simple query ever.
I have a database called CODE and in that is a table called
Connections and in that table a column called Category_Id
I need to be able to search for all the records with a value of 61 in
the Category_Id column and change them all to a value of 25
If any one could point me in the right direction that would be great
thanks.
SQL Server38
|
|
|
|
|
Tom
|
Posted: Sat Apr 07 19:26:46 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
Try:
use CODE
go
update Connections
set
Category_Id = 25
where
Category_Id = 61
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
I know absolutaley nothing of SQL scripting and need what is probably
the most simple query ever.
I have a database called CODE and in that is a table called
Connections and in that table a column called Category_Id
I need to be able to search for all the records with a value of 61 in
the Category_Id column and change them all to a value of 25
If any one could point me in the right direction that would be great
thanks.
|
|
|
|
|
Hari
|
Posted: Sat Apr 07 19:53:30 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
Hello,
To add on Tom, before you do any data change to production data please go
thru various DML commands and its usage.
Thanks
Hari
>I know absolutaley nothing of SQL scripting and need what is probably
> the most simple query ever.
>
> I have a database called CODE and in that is a table called
> Connections and in that table a column called Category_Id
>
> I need to be able to search for all the records with a value of 61 in
> the Category_Id column and change them all to a value of 25
>
> If any one could point me in the right direction that would be great
> thanks.
>
|
|
|
|
|
Haydar
|
Posted: Sat Apr 07 23:59:39 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
Hello,
If you are new to in SQL, you can learn easily and fast SQL from
http://www.w3schools.com/ web adress and you can also try to run SQL
statements in this web site. In additon that you can try your own SQL
staments and so on.:)
--
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net
>I know absolutaley nothing of SQL scripting and need what is probably
> the most simple query ever.
>
> I have a database called CODE and in that is a table called
> Connections and in that table a column called Category_Id
>
> I need to be able to search for all the records with a value of 61 in
> the Category_Id column and change them all to a value of 25
>
> If any one could point me in the right direction that would be great
> thanks.
>
|
|
|
|
|
E-ZU
|
Posted: Mon Apr 09 06:09:06 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
Thanks that worked, however my problem now is that I need to run
multiple instances of this e.g:
--- UPdate The Connections Table Category ID's
--- Category = Health & Medicine
update Connections
set
Category_Id = 60
where
Category_Id = 33
----------------------------------------------------------------------
--- UPdate The Connections_Summary Table Category ID's
--- Category = Health & Medicine
update Connections_Summary
set
Category_Id = 60
where
Category_Id = 33
-----------------------------------------------------------------------
--- UPdate The Connections Table Category ID's
--- Category = Health & Medicine
update Connections
set
Category_Id = 60
where
Category_Id = 135
----------------------------------------------------------------------
--- UPdate The Connections_Summary Table Category ID's
--- Category = Health & Medicine
update Connections_Summary
set
Category_Id = 60
where
Category_Id = 135
-----------------------------------------------------------------------
--- UPdate The Connections Table Category ID's
--- Category = Infrastructure
update Connections
set
Category_Id = 61
where
Category_Id = 51................and so on for about another 100
ID's
The problem now is keep getting a "query timeout expired" error after
it's been running for about 1 minuet
It's like it's trying to do too much at once, do I need to tell it to
wait for each cange to succeed? And if so how do i do that.
Thanks again for all your help : )
Paul
|
|
|
|
|
Erland
|
Posted: Mon Apr 09 06:32:37 CDT 2007 |
Top |
SQL Server Developer >> The most simple question ever
> Thanks that worked, however my problem now is that I need to run
> multiple instances of this e.g:
Well, it's difficult to answer your real question, when you don't ask
it. :-)
> --- UPdate The Connections Table Category ID's
> --- Category = Health & Medicine
> update Connections
> set
> Category_Id = 60
>
> where
> Category_Id = 33
> where
> Category_Id = 51................and so on for about another 100
> ID's
>
> The problem now is keep getting a "query timeout expired" error after
> it's been running for about 1 minuet
>
> It's like it's trying to do too much at once, do I need to tell it to
> wait for each cange to succeed? And if so how do i do that.
CREATE TABLE #changes (oldid int NOT NULL PRIMARY KEY,
newid int NOT NULL)
INSERT #changes(oldid, newid)
VALUES (33,60)
INSERT #changes(oldid, newid)
VALUES (135,60)
...
UPDATE Connections
SET Category_ID = t.newid
FROM Connections C
JOIN #changes t ON C.Category_ID = t.oldid
--
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
|
|
|
|
|
Erland
|
Posted: Mon Apr 09 06:33:32 CDT 2007 |
Top |
|
|
|
|
|