January 8, 2009 at 3:58 am
Hello All,
I have to do the following: before an insert or update is made to a range of dynamic columns in a sql database, check the datatype of the column to get the maximum size (number of characters it can hold) and then compare whatever a user wants to enter, to this value, to make sure the data we want to insert is within range. However I am having trouble writing a sql query that can do this. Could anyone please provide me with some pointers?
Thanks in advance
January 8, 2009 at 4:12 am
the way you are inserting/ updating records is not feasible. it alway a good practice to have the length validation from Application side restrict the user to enter available space or what you can also specify the character length in SP usiong string datatypes.
Abhijit - http://abhijitmore.wordpress.com
January 8, 2009 at 4:15 am
yes, maybe it is not the best way to do it, but it has to be done that way;)
January 8, 2009 at 4:30 am
This query returns the column name,datatype and length of the columns of a particular table.
select s.name , t.name ,s.max_length
from sys.columns s inner join sys.types t on s.system_type_id = t.system_type_id
where object_name(object_id) = 'tablename' and t.name <> 'sysname'
Modify it to suit ur requirements.
"Keep Trying"
January 8, 2009 at 4:46 am
absolutely FANTASTIC!!
Thank you very much, this is exactly what I was looking for.
I'm writing a java program, and in order to make the functionality as dynamic as can be, obviously the coding is a bit more complicated... but having this information will make my life much easier:hehe:
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply