user6596208
user6596208

Reputation: 1

I created table and cannot update in SQL server

I created a table and try to perform a basic update, but the result is 0 . Here is the script:

Create Table Working_Table 
   (Tot_Rec decimal(18,3),
    Tot_Bad_Rec decimal(18,3),
    Field_DQ_Score decimal(18,3),
    Tab_Name nvarchar(50) NULL
   );

   update Working_Table 
   Set Tab_Name = 'y';

Result

is " (0 row(s) affected)

Additionally, when I run the following the rules is 0. I would like to have a result in percentage value, but event in decimal it does not display. The table parameters are above. The values are (11-2)/11

(Select ([Tot_Rec]-[Tot_Bad_Rec])/[Tot_Rec]from [dbo].[Working_Table]
);

Thank you.

OK

Upvotes: 0

Views: 60

Answers (1)

giro
giro

Reputation: 431

Since you have no values in your table you can't update a row. What you're probably looking for is INSERT INTO ...

so maybe you could use

INSERT INTO Working_Table VALUES (0,0,0,'y')

or

INSERT INTO Working_Table (Tab_Name) VALUES ('y');

Part 2 If you want to divide sth. then you should probably add the following constraint to your Tot_Rec column, to prevent errors caused by an attempt to divide by zero.

ALTER TABLE Working_Table ADD CONSTRAINT Tot_Rec_Not_0 CHECK (Tot_Rec <> 0)

If that doesn't suffice post the error shown.

Upvotes: 2

Related Questions