Professional Web Applications Themes

set iValCount = exec(sSQL) ... ERROR - Microsoft SQL / MS SQL Server

Hi I have this code: .... Declare sSQL nvarchar(1000) Declare iValCount int set sSQL = '(SELECT count(id) FROM it_reg_utrustning_kringut AS kringut WHERE ' + sParameters + ')' set iValCount = exec(sSQL) .... The sParameters is a string with alot of and, or. If i just run the select i get what i want, a number. but i have to have this number in a variable. Tanks for any help /Anders...

  1. #1

    Default set iValCount = exec(sSQL) ... ERROR

    Hi

    I have this code:
    ....
    Declare sSQL nvarchar(1000)
    Declare iValCount int

    set sSQL = '(SELECT count(id) FROM
    it_reg_utrustning_kringut AS kringut WHERE ' +
    sParameters + ')'

    set iValCount = exec(sSQL)
    ....

    The sParameters is a string with alot of and, or. If i
    just run the select i get what i want, a number. but i
    have to have this number in a variable.

    Tanks for any help
    /Anders
    Anders Guest

  2. #2

    Default Re: set iValCount = exec(sSQL) ... ERROR

    Make use of sp_executesql.
    See following example:
    Declare DynamicSql nvarchar(1024), TotalRecords int ,TableName
    varchar(256)
    select tablename='customers'
    select DynamicSql = 'Select TotalRecords = COUNT(*) FROM '+ TableName
    exec sp_executesql dynamicsql, N'TotalRecords int output', TotalRecords
    output
    print totalrecords

    --
    -Vishal
    "Anders" <com> wrote in message
    news:0c3a01c3511c$3cb53ab0$gbl... 


    Vishal Guest

  3. #3

    Default set iValCount = exec(sSQL) ... ERROR

    Tanx

     
    >.
    >[/ref]
    Anders Guest

Similar Threads

  1. Replies: 4
    Last Post: November 28th, 10:12 PM
  2. EXEC in TSQL stored proc causes ERROR
    By don schilling in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: September 29th, 09:06 PM
  3. first time using exec() - are getting p error.
    By Anders Thoresson in forum PHP Development
    Replies: 3
    Last Post: August 17th, 02:16 PM
  4. Unix Systems Programming Newbie - exec format error
    By Gabriel in forum UNIX Programming
    Replies: 8
    Last Post: July 17th, 03:02 PM
  5. Replies: 0
    Last Post: December 10th, 09:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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