problem with advance query

problem with advance query

  
     SELECT sum ({Al_HourlyLeaves}.[HoursTaken]) As TotalHoursTaken
from {Al_HourlyLeaves}
where {Al_HourlyLeaves}.[SentBy] = @UserId

this is query its working in sql perfectly,but gives error in service studio...
actually i want to take sum of hours and assign this value to expression widget at show screen....

error:there is a mismatch between no of columns selected,and out put structure in GetSumOfTakenHours(its query name)....

any help pleas.... 
 Regards..
Israr
Have you set an output for the query at all?

Best regards,
PC
hi
i have set the entity as output structure,and an input parameter user id,
and thank you so much for the reply,,,...



Regards 
Israr
Hello Israr.

First, that is a warning, it should not stop you from running the code, but the warning itself means that the AI_HourlyLeaves structure has more (or less, but less then 1 item should be an error) items in the structure that are not being used

For istance, if your structure would be:
AI_HourlyLeaves
   counter: Integer
   someotherfield: text

The way to solve this would be to change your query into something like:
SELECT sum ({Al_HourlyLeaves}.[HoursTaken]) As TotalHoursTaken, "" As someotherfield
from {Al_HourlyLeaves}
where {Al_HourlyLeaves}.[SentBy] = @UserId


Another way to solve it it's to have your structure AI_HourlyLeaves with only one field of decimal/integer type.

Best regards,
PC
Ah, something I forgot...the order of the fields in the output structure matters...

If you had something like
AI_HourlyLeaves
   someotherfield: text
   counter: Integer

Then your query should be something like
SELECT "" As someotherfield, sum ({Al_HourlyLeaves}.[HoursTaken]) As TotalHoursTaken
from {Al_HourlyLeaves}
where {Al_HourlyLeaves}.[SentBy] = @UserId


Best regards,
PC
Thank You For Replying,
i will try these option,and it seems to be solved...

Regards 
Israr
Thank you PC....
its solved..
i was adding entity in Output Structure....that why was problem...
i created a structure with one atribute and solved...

Best Regards 
Israr A. Khan
Excelent, glad I could help :)

Best regards,
PC