Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    1

    Unanswered: Problems with passing columnname to Function

    Hey,
    i got a problem in my MS SQL Function. I want to pass the columnname to my function. But it does not work. If i typing the columnname directly in the function it works. But with a parameter i get an error that the Operanddatentyp varchar is not valid for the sum-Operator. This is my function:

    Code:
    ALTER Function SumforHauptgruppe(@column char(32), @ID int)
    returns decimal(18,2)
    as
    begin
    	declare @rv decimal(18,2)
    	SELECT @rv = sum(@column) from
    	InvestDaten 
    	WHERE Parent in (
    	SELECT ID FROM investTreeTable
    	WHERE PARENT = (
    	SELECT parent 
    	from investTreeTable
    	where ID = @id))
    	return @rv
    end
    Maybe one of you have a solution for the problem!!

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Very simple - you can't do that. The column names are part of the statement, they are not expressions, so you can't parameterise them.

    Please could you explain in simple English exactly what you are doing with the query? What does it do and why?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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