Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does Precision = 10 for INT datatype mean?

Status
Not open for further replies.

Coder7

Programmer
Joined
Oct 29, 2002
Messages
224
Location
US
I found some info in this forum but I don't understand yet.

If precision indicates the maximum number of digits the variable can contain, then I don't understand why the datatype used for this variable in a stored procedure = varchar(30).

I do understand that length = 4 means that the value will be stored in 4 bytes.

Thanks for any clarification, as always, and have a great day!

 
I'm a bit confused by your question(s). An int data type has a length of 4 - this is how much storage space (in bytes) it takes on the disc. It also has a precision of 10 - this is how many digits the number can contain.

Where does the variable of varchar(30) come in to things? --James
 
The highest value that can be stored in an int column has 10 digits but not all values with 10 digits can be stored. To say that an int has precision 10 is inaccurate in my opinion.

It would be sufficent to use varchar(11) to represent all possible values that can be stored in an int.
 
Everything was set up by someone else and I'm trying to understand what it all means.

the column = answer_value
in the sql server database, the datatype is INT and the length = 4 and the precision = 10

in the stored procedure that inserts the value of answer_value into the database, he indicates @answer_value = varchar(30)

I need some help sorting this out. Thanks.
 
The value will always be stored in the data type of the column. Usually you would make any variables in your SPs have the same data type as the column they will be inserted into but SQL Server will handle the conversion so long as it contains numeric data.

Ideally in this case you would change the variable to int. --James
 
The only reason I could see for using a varchar would be if I expected the input data to include character data and then I had a process to send the integer data to the table and do something else with the character data. If you don't have this situation, I would alter the stored procedure to take integer inputs. Be aware that this may mean making a change in the user interface too. The variable that it sends to run the stored procedure may need adjusting to match up and the validation on the form should be there to make sure only integer values are entered.
 
My specific question is how can you use varchar(30) - allow 30 characters - if the precision is 10 which only allows 10 characters maximum?

This is eluding me....thx again!
 
You can't! You would be able to pass a value into the procedure which had more than 10 digits but you would get an error when it actually tried to insert it into the table. --James
 
You can't. That's why it was suggested you change it. Whoever wrote this, wrote buggy code and obviously didn't do a very good job of testing either or would have noticed this. The only way this is valid is, as I said before, if he is taking the values which won't fit in the integer field and doing something else with them.
 
Thank you very much..you have confirmed my suspicion!!

Have a fantastic day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top