473,396 Members | 1,676 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.

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 1331
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.washington.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****@sommarskog.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
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.
Thanks Erland; now where do I send the money :)

Tony.

--
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 #11
Erland Sommarskog wrote:
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.
You might want to read the many comments about Tony's behaviour
in the groups where he posts by people other than myself and Joe
Celko. He has been universally rude.

If perhaps he is kinder to newbies making their first stumbling
attempts to use SQL Server perhaps that is because they don't
know enough to threaten his apparently fragile veneer.

He seems to forget my proximity to Redmond and my close relationships
with many on the Microsoft campus. His reputation there is far from
unblemished.
--
Daniel A. Morgan
University of Washington
da******@x.washington.edu (replace x with u to respond)
Jun 27 '08 #12
DA Morgan (da******@psoug.org) writes:
You might want to read the many comments about Tony's behaviour
in the groups where he posts by people other than myself and Joe
Celko. He has been universally rude.
Since I know Tony personally, and you don't, I may be better equipped
to determine wheher he is "universally rude" or not.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.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 #13
--CELKO-- wrote:
>>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).
This aspect of the data and logic is comparable to a data warehouse;
updated infrequently, queried frequently. On top of that, the updates
are performed by my client's employees (data) or me (logic), while the
queries are performed by my client's customers (while using my client's
web site) who will naturally be much less tolerant of delays. And the
timed jobs (add new rows every 15 minutes, refresh the whole thing every
24 hours) are set-based, at least.
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.
The base software is off-the-shelf; I can't change its database
structure (huge amounts of related front-end programs would have to
be changed to match), I can only add to it. The irregular inventory
item numbers are entrenched by years of previous use; I can't change
them, so the alternatives were (a) require additional data entry on
an ongoing basis, or (b) write logic to take advantage of the informal
near-standards.
Jun 27 '08 #14
DA Morgan <da******@psoug.orgwrote in news:1212078962.143106
@bubbleator.drizzle.com:
>
You might want to read the many comments about Tony's behaviour
in the groups where he posts by people other than myself and Joe
Celko. He has been universally rude.
Which has nothing to do with whether he is correct, which
is what is really important, for people trying to get actual
work done.

Jun 27 '08 #15

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

Similar topics

8
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...
2
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...
9
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...
7
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,...
6
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...
9
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...
2
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...
5
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...
2
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...
3
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
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.