Please help! My SQL statement doesn't work..

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Please help! My SQL statement doesn't work..

    It should be simple but this is the first time for me trying to use store
    procedure, can someone help correcting my syntax? I'm trying to do some looping
    in my store procedure: declare @loopnumber int declare @dbname varchar
    select @loopnumber = 1 select @dbname = 'MYDB_' + CAST(@loopnumber) While
    @loopnumber < 10 BEGIN /* SQL query here */ I put a create DB statement here
    select @loopnumber = @loopnumber + 1 END I got error from SQL server saying
    that: Server: Msg 1035, Level 15, State 10, Line 5 Incorrect syntax near
    'CAST', expected 'AS'. Server: Msg 170, Level 15, State 1, Line 11 Line 11:
    Incorrect syntax near '@dbname'. The strange thing is, when I run this query,
    1 database get created despite of the error and it is not looping as expected.
    The database name supposed to be MYDB_1, MYDB_2 etc instead I got 1 complete
    database with all the tables created but the name of the new database is
    @dbname How can I make this loop work? it seems so simple, I've check SQL book
    and I have no syntax error as far as looping What I'm not sure of is how to
    convert numeric datatype to nvarchar, is using CAST( ) not allowed? Please
    help!!!!!!

    alecken Guest

  2. Similar Questions and Discussions

    1. Problem getting sql statement logging to work
      Hi I am trying to log my sql statements to the syslog file. I have the following entries in my postgresql.conf file yet it doesn't seem to log...
    2. Links don't work in Shockwave movie but work in p
      Hi, everyone: I encountered a strange problem. I downloaded a sample movie from Macromedia site and noticed that the same problem occurs what I had...
    3. Simple PHP & MySQL Insert Statement Does Not Work
      Hello, I'm having a bear of a time figuring out why a simple PHP/MySQL insert is causing a parse error when trying to insert static data, and no...
    4. if statement does not work ?
      An insignificant noise sounding like Sandwick said: Replace the two if statement lines with the one line below $color == "#fffe10" ? $color =...
  3. #2

    Default Re: Please help! My SQL statement doesn't work..

    I am not to familiar with MY SQL but in SQL Server the problem would be that
    the line select @dbname = 'MYDB_' + CAST(@loopnumber) should be select
    @dbname = 'MYDB_' + CAST(@loopnumber as varchar(20)) The following should work
    as well select @dbname = 'MYDB_' + CAST(@loopnumber as varchar)

    dmuniz Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139