简体   繁体   中英

Parameter to filter query results

I have the following query below, and I am trying to filter results using an input parameter.

I am trying to either display all, or a specific servername and its corresponding info.

This is what I have:

DECLARE @p_ServerName varchar(10)
DECLARE @p_Env nvarchar(10)
DECLARE @p_EnvCat nvarchar(10)

SELECT     BlockSize, BootVolume, Compressed, SystemName, Label, Caption, PageFilePresent,
           [dbo].[CCS_DIGITAL_STORAGE_CONVERTER]('B', 'GB', Capacity) AS Capacity,
           [dbo].[CCS_DIGITAL_STORAGE_CONVERTER]('B', 'GB', FreeSpace) AS [Free Space], 
           [dbo].[CCS_DIGITAL_STORAGE_CONVERTER]('B', 'GB', Capacity - FreeSpace) AS [Used Space],
           100 * FreeSpace / Capacity AS [Free Space %],

           [CLE_ENV_SHORT], [CLE_ENV_CAT_SHORT]

FROM       CCS_Win32_Volume, [dbo].[CCS_V_SERVER_INSTANCE_DETAILS]

WHERE SystemName = @p_ServerName

In ssrs the preview shows no results. Can anyone help me with this? I am assuming there is something wrong with the WHERE clause? And perhaps also the way i set up the parameter :S

If you're trying to test your query in management studio you need to assign a value to your local variable. It is currently NULL and even if there are NULL values in that column you can't use the equals operator to match NULL so you're going to get zero results.

When you use that query in SSRS you'll want to remove the local variable declarations as they aren't needed. SSRS will effectively create local variables with the values given to the parameters. Declaring the variables in the query used in SSRS will either give you an error or no results.

In short: Assign a value to your local variables when testing in SSMS. Remove the local variable declarations when using the query in SSRS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM