Validating State abbreviations using a Check Constraint

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brown3313
    New Member
    • Aug 2006
    • 4

    Validating State abbreviations using a Check Constraint

    I want to make sure that valid US states are input in my database. Can someone provide exampleas of a check constraint to do this. If not a check constraint are there any hard code examples?
  • lipsa
    New Member
    • Aug 2006
    • 35

    #2
    hi,
    do the following.
    1.var_state_nam e variable holds the entered state name
    2.have a temp table(<state_ta ble>).which have a column(<state_n ame>) of US states.
    3.now check the entered state name.
    select count(*) from <state_table> where <state_name>='v ar_state_name'
    4.if the query returns value 1(assuming 1 state name occurs once inthe table),that means the entered state is a valid state name.and u can follow rest of the code
    if its 0,then no such state name exists,n you can give necessary message

    hope it works,may have better approach.
    Regards,
    Lipsa

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      How about since it looks like someone is inputting this data, why not have a drop down list that lists the states that you can select not manually inserted.

      Comment

      Working...