SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


need help on Expression syntax


need help on Expression syntax

Author
Message
Sharon S
Sharon S
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 162
Hi all,
I am trying to create the Expression equivalent of the following query:

SELECT count(TasksName)
FROM [db].[dbo].[testdetails]
where TopLevelProjectName = '40 Project Folder'
and TasksName = 'Project Info'


I basically need a working version of this incorrect syntax:
=CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

Thanks in advance,
Sharon
murdakillemall
murdakillemall
SSC Veteran
SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)

Group: General Forum Members
Points: 257 Visits: 426
Just curious, what's wrong with the SQL or better stated, why can't you use it?
davoscollective
davoscollective
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1607 Visits: 1008
Sharon S (3/8/2013)
Hi all,
I am trying to create the Expression equivalent of the following query:

SELECT count(TasksName)
FROM [db].[dbo].[testdetails]
where TopLevelProjectName = '40 Project Folder'
and TasksName = 'Project Info'


I basically need a working version of this incorrect syntax:
=CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

Thanks in advance,
Sharon


The expression you've suggested is different to the query. The SQL will count every non-null occurance of the field "TasksName" that has the fields TopLevelProjectName = '40 Project Folder'
and TasksName = 'Project Info' on the same row.

A CountDistinct in an SSRS expression will count distinct instances of a field. Which field are you counting? Counting TasksName distinctly where you've specified it must be equal to "Project Info" is not going to work. For example if you did something like this:

=CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info",Fields!FieldToBeCounted.value,Nothing))



You would need to specify a third column that might have different distinct info in it that you want to be counting. If you used the TasksName field, then this expression would always return 1 (or possibly 0 if no rows had both of those criteria). I don't think that's what you want here.

If you use a different FieldToBeCounted, and it has data that repeats then again the CountDistinct might not be what you want. You might just want a Count, and if so you could then use TasksName.

It helps to explain why you want to do this, because just giving you this answer might actually not help you at all and produce a sub-optimal outcome for you.
wolfkillj
wolfkillj
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2618 Visits: 2582
Sharon S (3/8/2013)
Hi all,
I am trying to create the Expression equivalent of the following query:

SELECT count(TasksName)
FROM [db].[dbo].[testdetails]
where TopLevelProjectName = '40 Project Folder'
and TasksName = 'Project Info'


I basically need a working version of this incorrect syntax:
=CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

Thanks in advance,
Sharon


You could try something like this (I'm not at a computer with BIDS right now, so I can't be certain my syntax is EXACTLY right :-) ):

=Sum(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder", IIF(Fields!TasksName.Value = "Project Info", 1, 0), 0))

The nested IIFs test your conditions - if both are TRUE, they return 1; if not, they return 0. The SUM function then adds up all the 1s and 0s, and the total equals the number of rows where TopLevelProjectName = "40 Project Folder" and TasksName = "Project Info".

Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search