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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problems with creating rule

Author  Topic 

sanlen
Starting Member

29 Posts

Posted - 2008-10-23 : 05:15:18
Hi All,

i am trying to create rule in the SQL server with the following code:

CREATE RULE phone_rule
AS
@phone LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]'

EXEC sp_bindrule phone_rule,'Employee.phone'
EXEC sp_bindrule phone_rule,'Client.phone'

however, i got the error as the following:

Msg 156, Level 15, State 1, Procedure phone_rule, Line 5
Incorrect syntax near the keyword 'EXEC'.


I tried to figure out the problems but it does not work.

Could you please advise what are the problems with the above codes?

Thanks you very much for your time and any advise you may give me.

Best Regards,
SANLEN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 05:18:35
is this the only code you executed? can try putting GO between two EXEC statements?
Go to Top of Page

sanlen
Starting Member

29 Posts

Posted - 2008-10-23 : 05:53:17
Hi,

Yes, it is the only code that i tried to execute. After i added GO then i got the following error:

Msg 156, Level 15, State 1, Procedure phone_rule, Line 5
Incorrect syntax near the keyword 'EXEC'.
Msg 15017, Level 16, State 1, Procedure sp_bindrule, Line 105
The rule 'phone_rule' does not exist.

Best Regards,
SANLEN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 06:04:53
tried this too
CREATE RULE phone_rule
AS
@phone LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]'
GO

EXEC sp_bindrule 'phone_rule','Employee.phone'
EXEC sp_bindrule 'phone_rule','Client.phone'
Go to Top of Page

sanlen
Starting Member

29 Posts

Posted - 2008-10-23 : 06:08:33
Hi,

It is working now, thanks you very much for your time and all the good advise that you been giving me. By the way, could you please also explaine what is the different between with GO and without GO?

Thanks

Best Regards,
SANLEN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 06:11:57
quote:
Originally posted by sanlen

Hi,

It is working now, thanks you very much for your time and all the good advise that you been giving me. By the way, could you please also explaine what is the different between with GO and without GO?

Thanks

Best Regards,
SANLEN


GO is statement batch seperator. When you use it makes sure you've created the rule prior to using it. sincle you're doing all of then together they will get executed simultaneously. so there will be chace that EXEC wont identify the rule as it will not created while execution started.
Go to Top of Page
   

- Advertisement -