return single value from order of other columns in one query

  • I'm learning SSRS and SQL and currently I need a single value for a default value in a user prompt.

    The recommended way to get this value is with another DataSet in SSRS.

    But I don't know how to make a single query return a single value from a row, while using other columns to derive that row.

    For example if I have 3 columns, firstName, lastName, employeeID, and I want to sort on the combined names and return just that resulting ID - how can I do that?

    So how would I change this into something that just returns the employeeID of the TOP row:

    SELECT [firstName] + N' ' + [lastName] as fullname

    ,[employeeID]

    FROM [playzone].[dbo].[NamesTest]

    ORDER BY [lastName] ASC

    Thanks

  • Here you go:

    https://msdn.microsoft.com/en-us/library/ms189463.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks for responding.

    I knew of TOP. But I didn't want one row. Which is why I wrote

    return a single value from a row

    .

    Anyways the SSRS dialogs for setting that parameter from a query expected a single value and gave me the option of just selecting that value/column from the resulting data (one row). Which TOP(1) provided.

    So I didn't need to make the query return a single value as I'd thought. A single row sufficed.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply