Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-09-13 : 06:34:24
|
| Luke writes "HiI am brand spanking new to SQL and havent much knowledge on how to do simple things.Is there a way of running a script that would throw up an error if there were more than 10 characters and less than 10 characters?I am thinking Left count and Right count type of commands?Many thanks for any help you can offer.Luke" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-09-13 : 06:42:32
|
Why bother with LEFT() or RIGHT()? Use LEN()If len(@Param) <> 10 then RAISERROR('Param must be 10 characters long', 16, 1)Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-09-13 : 09:04:49
|
| [code]USE NorthwindGOCREATE TABLE dbo.myTable99 ( Col1 char(10) NULL ) ON [PRIMARY]GOALTER TABLE dbo.myTable99 ADD CONSTRAINT CK_myTable99 CHECK (LEN(Col1)=10)GOINSERT INTO myTable99(Col1) SELECT '1234567890'GOSELECT * FROM myTable99GOINSERT INTO myTable99(Col1) SELECT '1'GODROP TABLE myTable99GO[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-09-13 : 09:08:20
|
| If you send data from front end then validate thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|