• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2180
  • Last Modified:

SQL Question

I'm having trouble with this quetion can anyone help me undestand how to come to come to the answer.

Add a field named Allocation to the Part table. The allocation is a number representing the number of units of each part that have been allocated to each customer. Set all values of allocation to zero. Calculate the number of units of part number KV29 currently on order. Change the value of allocation for part number KV29to this number. Display all the data in the Part table.

ALTER TABLE Part
ADD Allocation CHAR (0)
UPDATE Part
SET Allocation= some number
WHERE PartNum= some number
;
0
rwill357
Asked:
rwill357
  • 2
1 Solution
 
käµfm³d 👽Commented:
I believe the line

   ADD Allocation CHAR (0)

is asking for a column that is zero characters big--which I don't think is possible (could be wrong though).

I believe what you want is something more like the following. Please note:  "allocation_table" should be replaced with the name of the table holding the part allocation entries and "part_number" should be replaced with the name of the column in Part and the name of the column in "allocation_table" that represents part number (these may be different between the two tables). The "part_number" field that is inside the parentheses should be replaced with the column name from the "allocation_table"; the field outside of the parentheses should be replaced with the column name from the Part table.
ALTER TABLE Part
ADD Allocation INT;

Go

UPDATE Part
SET Allocation = 0;

Go

UPDATE Part
SET Allocation = (SELECT COUNT(1) FROM [allocation_table] WHERE part_number = 'KV29')
WHERE part_number = 'KV29';
WHERE PartNum= some number;

Open in new window

0
 
käµfm³d 👽Commented:
Correction to the last update:
UPDATE Part
SET Allocation = (SELECT COUNT(1) FROM [allocation_table] WHERE part_number = 'KV29')
WHERE PartNum = 'KV29';

Open in new window

0
 
HackneyCabCommented:
You can define a CHAR(0) but such a field can only store an empty string or NULL. Which does not appear to suit the requirement you describe.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now