473,388 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Please help with this SQL statement

Expand|Select|Wrap|Line Numbers
  1. declare @parm nvarchar (20)
  2. declare @mean float
  3.  
  4. set @parm = 'Q' + rtrim(@qNumber)
  5. set @query='select @mean=Avg(cast('+@parm+' as float)) from myTable)
  6. exec @query
  7.  
  8.  
error msg:Must declare the variable '@mean'.

the message is confusing, because @mean is declared at the first line. Can anybody explain a little bit. Thanks for any inputs.
Dec 4 '07 #1
1 985
Jim Doherty
897 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. declare @parm nvarchar (20)
  2. declare @mean float
  3.  
  4. set @parm = 'Q' + rtrim(@qNumber)
  5. set @query='select @mean=Avg(cast('+@parm+' as float)) from myTable)
  6. exec @query
  7.  
  8.  
error msg:Must declare the variable '@mean'.

the message is confusing, because @mean is declared at the first line. Can anybody explain a little bit. Thanks for any inputs.
Hi Annie,

Yes but @mean has no meaning if used within the string as given there? something like the below returns a column value if this is what you are trying to do? I've set @qNumber because I don't know where qNumber derives its source value from in your example.
In addition, in your example you are trying to cast to numeric 'float' a concatenated 'Q' with a numeric value? can't be done am afraid numeric is numeric if I am understanding your example logic correctly?

declare @qNumber nvarchar(45)
declare @parm nvarchar (20)
declare @mean float
set @qNumber='300 '
set @parm = rtrim(@qNumber)
select @mean=Avg(cast(@parm as float)) from myTable
select @mean as mycolumn

Regards

Jim :)
Dec 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
2
by: Amanda | last post by:
From a guy in Microsoft newsgroups: | In *comp.databases.ibm-db2* there are always IBM guys | from the Toronto labs on line.Post with the | -for the love of god please help- | line...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
30
by: Jake Forson | last post by:
Hi there, Before I notify MSFT, can someone confirm this is in fact a compiler bug (it seems pretty obvious but I'm fairly new to C#). The following code (erroneously) generates compiler error...
5
by: Michael Kintner | last post by:
I am trying to use a IN statement Select * From ShowMenusFirst WHERE (Security In ((select Security from Users Where (Username='mkintner')))) ORDER BY Menus.Level; The results from the query...
1
by: David | last post by:
Hi, I cannot get the following (MS Access) SQL statement working in my asp page, please can anyone help me ? Thanks :-) ------------------------------------------------ <% strQuery =...
9
by: martien friedeman | last post by:
I have written this tool that allows you to look at runtime data and code at the same time. And now I need people to test it. The easiest way to see what I mean is to look at some videos:...
14
by: bbawa1 | last post by:
It says invalid expression term && protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if...
14
by: donovans | last post by:
Hey there, First question: I really need help with debugging this code. I keep getting the java.sql.SQLException: General error, and am now lost at a solution to it...I get this with about 4 of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.