473,651 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with an Update Statment

CREATE Table CO(CustID int, OfficerSID varchar(10), OfficerRank
tinyint)

Insert Into CO
VALUES (1, 'KURT', 1)

Insert Into CO
VALUES (1, 'ALEX', 2)

Insert Into CO
VALUES (1, 'COLIN', 3)

Insert Into CO
VALUES (1, 'RUSTY', 4)

Insert Into CO

VALUES (2, 'CAL', 2)

Insert Into CO
VALUES (2, 'VIN', 4)
Insert Into CO
VALUES (3, 'FIDA', 2)

Insert Into CO
VALUES (3, 'ZOTO', 1)

Insert Into CO
VALUES (4, 'ZARA', 3)

Insert Into CO
VALUES (4, 'MAIR', 2)
Insert Into CO
VALUES (5, 'tara', 4)

Insert Into CO
VALUES (5, 'sara', 4)
I have an output table which is primarily like a temp table and then i
run my reports just grabbing data from this table.
This table looks like

CREATE Table tbl_Output (CustID int, OfficerSID1 varchar(10),
OfficerSID2 varchar(10))

I need this table to be populated thus
The offierSID1 needs to filled with officer who are ranked highest, be
it 1,2,3 or 4
Then comes OfficerSID2 which need to be filled with secondhighest
ranking, be it 1, 2, 3, 4
There can be two officersid with same ranking so then both of them
would appear in hte output table

The output table is already populated with CustID. so i need update
statements to fill in the officersids

So the output needs to look like
1, Kurt, Alex
2, Cal, Vin
3, Zoto, Fida
4, Mair, Zara
5, Tara, Sara or 5, Sara, Tara

Jun 27 '08 #1
14 1351
Plamen Thank you so much and to all, I apologize. I work on SQL 2000
and need a solution for that. Thank you
Jun 27 '08 #2
Thanks a bunch Plamen : It worked like a charm
Jun 27 '08 #3
The next question is why do you want to build a table that has to be
constantly updated when you can use a VIEW that is always right?
This is fundemental design - beginners 101.

Summary tables are used to assist performance and scalability.

It could often take 20 seconds - 5 hours to work out the aggregations
depending on the data set and the complexity of the calculations.

In OLTP data is read many many more times than it is written.

Now imagine your query method took 10 seconds to run for a single user; 100
users running the same query would flat line your CPU and probably push the
query time out into minutes - not very scalable.

Unfortunetly because you are classroom based you don't see these real world
problems; you are best getting out and doing a beginners programming job for
a couple of years to get the necessary fundementals.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]

Jun 27 '08 #4
Tony Rogerson wrote:
>The next question is why do you want to build a table that has to be
constantly updated when you can use a VIEW that is always right?

This is fundemental design - beginners 101.

Summary tables are used to assist performance and scalability.

It could often take 20 seconds - 5 hours to work out the aggregations
depending on the data set and the complexity of the calculations.

In OLTP data is read many many more times than it is written.

Now imagine your query method took 10 seconds to run for a single user; 100
users running the same query would flat line your CPU and probably push the
query time out into minutes - not very scalable.

Unfortunetly because you are classroom based you don't see these real world
problems; you are best getting out and doing a beginners programming job for
a couple of years to get the necessary fundementals.
I have to agree. (I say "have to" because I don't like agreeing with
people with a history of rudeness - though the above-quoted message is
less so than usual.) Anyway, recent real-world example:

* Inventory item numbers (e.g. 1234-BLUE) need to be parsed into
style, color, size (e.g. 1234, BLUE, n/a). Several dozen exceptions
are hardcoded into the logic.

* View took 2 seconds. Front end is web site, so this is too slow.

* Replaced view with a table that is refreshed from the view by a
SQL Server Agent job every 15 minutes. This level of near-real-time
is acceptable in context (short delay between new items being
approved and appearing on the site).
Jun 27 '08 #5
>Anyway, recent real-world example:

* Inventory item numbers (e.g. 1234-BLUE) need to be parsed into
style, color, size (e.g. 1234, BLUE, n/a). Several dozen
exceptions
are hardcoded into the logic.

* View took 2 seconds. Front end is web site, so this is too slow.

* Replaced view with a table that is refreshed from the view by a
SQL Server Agent job every 15 minutes. This level of near-real-
time
is acceptable in context (short delay between new items being
approved and appearing on the site).
<<

Ouch! That much refreshing, redundancy and uncertainty for 15 minutes
at a time sounds bad to me. Following one of my heuristics, bad DDL
leads to worse DML, and eventually to procedural coding, sequential
processing, cursors and other kludges (at this point I tell the joke
about Levant the Tailor and the suit that doesn't fit).

Why not normalize the table to 1NF instead? The style, color and size
seem to be attributes that define a 3-column key you call inventory
number. But you crammed them into a non-scalar column, so you are not
in 1NF. If you need to display them as a single string, then you can
add a VIEW or computed column for that purpose. This would avoid
those dozen exceptions and procedural logic, but you might need a
"moose killer" CHECK() constraint on the key for data integrity.

Jun 27 '08 #6
I have to agree. (I say "have to" because I don't like agreeing with
people with a history of rudeness - though the above-quoted message is
less so than usual.) Anyway, recent real-world example:
Ed - I'm rude purely to the likes of --celko-- because of his deeming and
dam right outlandishly bad attitude on this forum.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]

Jun 27 '08 #7
Tony Rogerson wrote:
>I have to agree. (I say "have to" because I don't like agreeing with
people with a history of rudeness - though the above-quoted message is
less so than usual.) Anyway, recent real-world example:

Ed - I'm rude purely to the likes of --celko-- because of his deeming
and dam right outlandishly bad attitude on this forum.
No Tony: You are uncivil, rude and lacking in social graces across
the board. Do not flatter yourself by thinking otherwise.

Every comment made about you in all of these groups, from people
from different countries and different cultures, all communicate
the same fundamental opinion ... you a almost always belligerent.

I doubt many, if any, of us have ever met you. The impression of you
we have is the one you have created. If you don't like that then the
onus is upon you to start with an apology.
--
Daniel A. Morgan
University of Washington
da******@x.wash ington.edu (replace x with u to respond)
Jun 27 '08 #8
DA Morgan (da******@psoug .org) writes:
No Tony: You are uncivil, rude and lacking in social graces across
the board. Do not flatter yourself by thinking otherwise.
Since I know Tony personally, I can assure you that he does not lack
social grace across the board. He might run a little run a little low
on it when he talks with people like you or Celko.

But he would never flame someone who have made his first stumbling
attempts to use SQL Server. In difference to you know who.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #9
No Tony: You are uncivil, rude and lacking in social graces across
the board. Do not flatter yourself by thinking otherwise.

Every comment made about you in all of these groups, from people
from different countries and different cultures, all communicate
the same fundamental opinion ... you a almost always belligerent.

I doubt many, if any, of us have ever met you. The impression of you
we have is the one you have created. If you don't like that then the
onus is upon you to start with an apology.
I actually thought twice about gracing your post with a response but I
thought I ought because you might learn something about yourself.

Lol, I can count on my right hand the number of people in the SQL Server
groups I'm ruded to - (1) celko; Oracle (3) - you, sybrand and hp; well -
anybody else who attacks me on there for posting truth, accurate and direct
posts.

Now, you on the other hand, well.... all too often people comment on your
uncivil, dictitorial attitude and biased opinions on the oracle groups; lots
of folk have sent me private emails congratulating me whenever I pick you up
on the misinformation and bad attitude you post around SQL Server.

I've been around for over a decade on the NNTP SQL Server groups and have
met most the other SQL Server MVP's and meet quite a lot of people in the UK
via SQLBits and the User Group I run; I know full well what people think of
me - don't you worry on that score.

As to an apology; well - to you, celko - no, I don't think that will be
forth coming; I treat people as they treat others.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3270
by: Cherrish Vaidiyan | last post by:
hello googles, I have a small sqlplus problem. i have created a table with date field along with other varchar2,number etc. But unfortunately i made a mistake in entering the date. for some date records i made an error in month... say for 20 record.Now i need to correct the month.HOW???? i have tried with 'update' statement using like,=,... etc.All resulted in failure.i thought of converting date datatype to character and then use the...
2
1958
by: Andrew | last post by:
I have a windows 2000 sv, with exchange 2000 running with IIS as well. I am tring to send an email with an attachment with CDO. Set cdoConfig = CreateObject("CDO.Configuration") with cdoConfig.Fields .Item(sch & "sendusing") = 2 ' cdoSendUsingPort .Item(sch & "smtpserver") = "spiternet.com" .update End With
9
2408
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
7
1880
by: Hal | last post by:
Hi, Please see http://webmonky.myby.co.uk/problem.JPG I have 1 Text Box in a form (ms access), one for an Order # .I currently have the form working so when I enter (or scan) an order number, that order number (which is a field in a record) is marked as DESPACTHED in a Tickbox Field under that record. Here is the code..
6
4295
by: Agnes | last post by:
For i = 1 to 5000 Me.txtCounter.text = i 'As I found the textbox didn't update itself, I add (Me.txtCounter.update) '.... some calculation statment end for Me.txtcounter.update sometimes work , sometimes doesn't , I saw the textbox show "289" and then stop , but the statment runs very well.
9
1724
by: Jeff Gardner | last post by:
Greetings: I have an UPDATE query (php 5.1.6/mysql 5.0.24a on apache 2.2) that appears to execute with no errors (php,mysql, or apache) but the data in the "UPDATED" table doesn't change. I've checked privileges for connecting account and that isn't an issue. Maybe it's my query: $editO = " UPDATE organization SET
2
1390
by: moz2407 | last post by:
Hi, I am fairly new to SQL statements and where as i can perform retriving types of queries i have been stuck on an UPDATE one for weeks now; quite frankly its making me pull what little hair i have left out! I was hoping that someone alot smarter than me would be able to help. I am trying to update a feild on one table based on 2 critera; one from the same table and another from another table. This is what i am trying to do in...
5
3211
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used at conventions. I have a main form with two subforms. On the main form, there is a text box that displays the sum of total orders entered in the subform, . I'm trying to create another text box on the main form, that looks at the subtotal...
2
18093
by: gimme_this_gimme_that | last post by:
I use the following SQL statment to bring z_emp_id values to a employee table: update employee set z_emp_id = (select z.emp_id from z.employee z where z.login=employee.login) Upon executing this statement a warning appears (in AQT) saying all the rows in the table will be modified. Is this a benign message?
3
3951
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.