Need help with creating a query to run in enterprise manager

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DivinDave
    New Member
    • Mar 2008
    • 2

    Need help with creating a query to run in enterprise manager

    Any help with this would be greatly appreciated. I need to create a query and my SQL skills are very very rusty.

    Lets say I have the following;
    Database name = users
    Table name = info1
    Table type is NVARCHAR 40
    Info1 can contain the following type of data;
    <NULL>, all numbers ie.. 111122223333444 4, or alphanumeric ie.. JAMISON/ JOHN8

    Here is my challenge. I need an update query to go through every record and if it is of type "all numbers" ie.. 111122223333444 4, I want to keep the last 4 numbers and replace the rest with 0. So the resulting record would be 000000000000444 4.

    Can one of you SQL genius's help me with this. I'm stumped.
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Try checking the SQL help files index for the function ISNUMERIC
    That should get you started.

    Comment

    • DivinDave
      New Member
      • Mar 2008
      • 2

      #3
      Originally posted by Delerna
      Try checking the SQL help files index for the function ISNUMERIC
      That should get you started.
      'Any other help? I REAlly am rusty and neeed a lot of help. THANKS!

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Originally posted by DivinDave
        Any help with this would be greatly appreciated. I need to create a query and my SQL skills are very very rusty.

        Lets say I have the following;
        Database name = users
        Table name = info1
        Table type is NVARCHAR 40
        Info1 can contain the following type of data;
        <NULL>, all numbers ie.. 111122223333444 4, or alphanumeric ie.. JAMISON/ JOHN8

        Here is my challenge. I need an update query to go through every record and if it is of type "all numbers" ie.. 111122223333444 4, I want to keep the last 4 numbers and replace the rest with 0. So the resulting record would be 000000000000444 4.

        Can one of you SQL genius's help me with this. I'm stumped.
        try:

        Code:
        update info1
        set YourColumn = right(replicate('0',16) + right(YourColumn,4),16)
        where isnumeric(YourColumn) = 1
        Just replace the column name.

        -- CK

        Comment

        Working...