Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2011
    Posts
    6

    Unanswered: Insert Country code into columns

    Hi All,

    Iam having a users table which contains "Mobile" column as well. I want a query to set the country code value by default into the column name so that the column should be updated with the mobile number along with the default country code. kindly help me on this

    Thanks,
    Ram

  2. #2
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    are u trying to decipher the country code from the mobile number of the user and update in country column?
    Cheers....

    baburajv

  3. #3
    Join Date
    Nov 2011
    Posts
    6

    hai

    hai,
    actually the country code for all the users wil;l be same +91 and i want it to show at the starting of the Mobile Number in the mobile column

    thanks,
    Ram

  4. #4
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    if thats the assumption, set '+91' as the default value for the countrycode column.

    just curious.. how do u ensure that the users key in their mobile numbers without countrycode? is the App, doing some validation on this?
    Cheers....

    baburajv

  5. #5
    Join Date
    Nov 2011
    Posts
    6

    hai

    hai,

    could you just let me know how to assign a default value to a column, iam new to this field it could be a great help for me.

    Thanks,
    Ram

  6. #6
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    if its an existing table you have to do two steps
    1. define the default constraint for the column and

    ALTER TABLE <tableName> ADD CONSTRAINT <ConstraintName>
    DEFAULT <DefaultValue> FOR <ColumnName> ;

    2. update the existing NULL values in the column to the default value

    Update <TableName> Set <columnName> = <defaultValue> where <columnname> is null


    If you are creating the table for first time, specify the default value along with table creation script

    Create table <tablename>
    (
    <column1> <datatype> DEFAULT <default value>
    ...
    );

    hope this helps

    Pls refer SQL BOL for more on ALTER TABLE..
    Cheers....

    baburajv

  7. #7
    Join Date
    Nov 2011
    Posts
    6

    hai

    Hi Babu,

    Thanks for your reply and i got 1 more issue now. By default iam able to get +91 now for the column but when i tried to pass it with mobile number +91 is getting removed, but i want the mobile number should be added to the +91.
    kindly help me on this.

    Thanks,
    Ram

  8. #8
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    could u pl explain the problem with an example?
    Cheers....

    baburajv

  9. #9
    Join Date
    Nov 2011
    Posts
    6

    hai

    Hai Babu,

    After altering the table with default value as '+91' all the values in the column are being updated with +91. Now when iam passing the mobile number(9000400112) value from the client application, for me the column value in the DBshould be updated as : '+919000400112' but it is being updated in the column as 9000400112(default value is getting eliminated). It is not appending to the default value.Kindly help me on this

    Thanks,
    Ram

  10. #10
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    my assumption was that you have a separate countrycode column in the table..

    something like

    tablename
    (
    ....
    countrycode varchar(5) default '+91',
    mobile# ...
    ...
    )

    if this is the case, the mobile number sent from client app goes to mobile# column and countrycode will be +91 by default.. for displaying the numbers in the UI, you must have a select query which concatenates the two columns

    select countrycode + mobile# from table ...


    does this answer your question?
    Cheers....

    baburajv

  11. #11
    Join Date
    Nov 2011
    Posts
    6

    hai

    thanks a lot babu..i will try and get back 2 u if had any queries. Iam really thankful to you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •