Add Symbol () in report ssrs - ssrs-2008

I have code :
CourseName + ' ' + isnull(GradeLevel,'')) as CourseName
The result :
Permit Working High 3
How to make result like this :
Permit Working High (3)

CourseName + ' ' +
CASE
WHEN GradeLevel IS NULL THEN ''
ELSE '(' + GradeLevel + ')'
END
AS CourseName

Related

Crystal Report - Query in formula

I have formula,
stringvar q1;
stringvar query;
q1 := "SELECT SHOW_CERT FROM C_SPEC_DELTA_REPORT_VIEW X WHERE X.VERSION = (select CONSTANT_VALUE from LIMS_CONSTANTS where name ='C_PRODUCT_VERSION1_DELTA') AND X.GRADE = ' " + {Command.GRADE} + " ' AND X.SAMPLING_POINT = ' " + {Command.SAMPLING_POINT} + " ' AND X.COMPONENT = ' " + {Command.COMPONENT} + " ')"
query := q1;
SQL( query )
Here, in the {command.COMPONENT} field, it the value in more than 30 Characters, my report execution is failing.
Is there is any length constraint? If Yes, how to extend it.
The length of the COMPONENT field is 160 characters in the DB.
Need your help!!!

Uniquename function in mdx script

I really need your help.
For a SSRS report, I have this mdx script:
select
{[Geographie].[Commune].[AHUY], [Geographie].[Commune].[BRETENIERE]} on columns
,{[Activite].[Branche].&[B], [Activite].[Branche].&[C]} on rows
from [ACSEL2]
where ([Measures].[CATTC], [Perimetre].[Perimetre].&[2], [Temps].[Annee].&[2006])
Please, I need to have the uniquename for the members that I have in columns
({[Geographie].[Commune].[AHUY], [Geographie].[Commune].[BRETENIERE]})
Please Can U help me to write this mdx script ?
Lidou
Declare a member using With statement, like this:
WITH MEMBER [Measures].[UniqueName] as [Geographie].[Commune].CurrentMember.UniqueName
Select
--Your select here
More details on CurrentMember
WITH
-- Geography metadata
MEMBER [Measures].[Geographie]
AS StrToValue ( #SelectionGeographie + ".Hierarchy.Currentmember.Uniquename" )
MEMBER [Measures].[Geographie_Label]
AS StrToValue( #SelectionGeographie + ".Hierarchy.CurrentMember.Member_Caption" )
SELECT NON EMPTY {
[Measures].[Geographie],
[Measures].[Geographie_Label],
[Measures].[11 VA]
} ON COLUMNS,
( STRTOSET ( "{" + #SelectionGeographie + "}") ,
STRTOSET ("{" + #SelectionActivite + "}" ))
ON ROWS
FROM [MyCube]
WHERE STRTOTUPLE ( "(" +#Annee + "," + #Perimetre + ")" )

How to format manipulated DateTime fields in dynamic TSQL

I have a query that looks basically like this, wrapped in a dynamic query to accommodate table names that can change. I got the date functions in the middle converted but it doesn't like the LoadedDateTime and CallPlacedTime at the end. I've tried every conversion and combination of quoting those lines that I can think of. How can I accomplish this?
DECLARE #sql_TotalDialsNewLeads nvarchar(1000) = N'
SELECT COUNT(*)
FROM ' + #tbl_CH + ' ch, ' + #tbl_CL + ' cl, ' + #tbl_DA + ' da
WHERE ch.IDENTITY = cl.IDENTITY
AND cl.CRMID = da.CRMID
AND CallPlacedTime BETWEEN ''' + CONVERT(varchar(30),DATEADD(HOUR,-#TimezoneOffset,#StartDate),126) + '''
AND ''' + CONVERT(varchar(30),DATEADD(HOUR,-#TimezoneOffset,#EndDate),126) + '''
AND Product = ''' + #Product + '''
AND Country = ''' + #Country + '''
AND DATEPART(DayOfYear,DATEADD(HOUR,-#TimezoneOffset,LoadedDateTime))
= DATEPART(DayOfYear,DATEADD(HOUR,-#TimezoneOffset,CallPlacedTime))'
EXECUTE(#sql_TotalDialsNewLeads);
Thanks,
Sean
Try to use sp_executesql with parameters instead of making string to execute manually:
...
AND CallPlacedTime BETWEEN DATEADD(HOUR,-#TimezoneOffset,#StartDate)
AND DATEADD(HOUR,-#TimezoneOffset,#EndDate)
...
and execute it with the following statement:
exec sp_executesql #sql_TotalDialsNewLeads,
N'#StartDate datetime, #EndDate datetime',
#StartDate,#EndDate;
Here is a MSDN guide. Also you can do it for other parameters in your SQL statement.
Instead of using the conversion outside use it inside the dynamic query.
something like this. (Not tested)
DECLARE #sql_TotalDialsNewLeads nvarchar(1000) = N'
SELECT COUNT(*)
FROM ' + #tbl_CH + ' ch, ' + #tbl_CL + ' cl, ' + #tbl_DA + ' da
WHERE ch.IDENTITY = cl.IDENTITY
AND cl.CRMID = da.CRMID
AND CallPlacedTime BETWEEN CONVERT(varchar(30),DATEADD(HOUR,'''+ -#TimezoneOffset +''','''+ #StartDate +'''),126)
AND CONVERT(varchar(30),DATEADD(HOUR,'''+ -#TimezoneOffset +''','''+ #EndDate +'''),126)
AND Product = ''' + #Product + '''
AND Country = ''' + #Country + '''
AND DATEPART(DayOfYear,DATEADD(HOUR,-#TimezoneOffset,LoadedDateTime))
= DATEPART(DayOfYear,DATEADD(HOUR,-#TimezoneOffset,CallPlacedTime))'
EXECUTE(#sql_TotalDialsNewLeads);

Append an integer to a string as a string

Trying to do something like this:
select 'Setup for Car ' + CAST(varchar(50), #CarID) + ' for user ' + CAST(varchar(5), #UserID)
doesn't work, not sure what the syntax would be then for T-SQL. I've hunted around, have not found it yet.
You can user either of these:
select 'Setup for Car ' + Convert(varchar(50), #CarID) + ' for user ' + Convert(varchar(5), #UserID)
OR
select 'Setup for Car ' + CAST(#CarID as varchar(50)) + ' for user ' + CAST(#UserID as varchar(5))
You are using CAST wrong. It should be
CAST(#Variable AS WhatYouAreCastingTo)
Here is a fiddle showing this
Remember, MSDN is your friend :)

Export all not in comparison table

I have been using the following export query (CTE) for a few years but a client has requested that we do not give them all of the data from the 'C' line as they do not need some of the data. I have all of the PlaintiffNames that they do not need but I have no idea how to adjust the query to exclude the PlaintiffNames they do not need. And using NOT IN as is shown below has not worked and I am guessing I am missing something!
SELECT 4 AS grpOrd
, null AS posInGrp
, 'C'
, A.CaseNumberKey
, 'C|' + IsNull(J.CType, '') + '|' + IsNull(J.plaintiffName,'') + '|' + IsNull(J.plaintiffAdd1, '') + '|' + IsNull(J.plaintiffCity, '') + '|' + IsNull(J.plaintiffState, '') + '|' + IsNull(J.plaintiffZip, '') + '|' + '|' + IsNull(J.defendantName, '') + '|' + IsNull(J.defendantAdd1, '') + '|' + IsNull(J.defCity, '') + '|' + IsNull(J.defState, '') + '|' + IsNull(J.defZip, '') + '|' + '|' + IsNull(J.Court, '') + '|' + IsNull(J.CaseID, '') + '|' + IsNull(J.JAmt, '') + '|' + IsNull(replace(convert(VarChar(10), JDate, 101), '/', ''), '') + '|' + IsNull(replace(convert(VARCHAR(10), revivedDate, 101), '/', ''), '') AS Extract
FROM newCityCollection.dbo.PropertyInformation A
JOIN Acme.new_judgment_system.dbo.selected_compiled_clean J
ON J.CaseNumber = A.CaseNumberKey
WHERE A.DateFinished BETWEEN #PeriodStart AND #PeriodEnd
AND ClientKey = 2
AND (J.plaintiffName NOT IN (SELECT Plaintiff FROM dbo.excluded_Plaintiffs))
I am getting invalid object name dbo.excluded_Plaintiffs when I try to run this. Note that is the very bottom of the CTE which has numerous lines but the issue is solely in this last line.
An example of a common plaintiff that they do not want is 'PHILA TRAFFIC COURT'
Is it possible to adjust the above to check the table (excluded_Plaintiffs) and exclude that data? I have tried to no avail and am hoping someone has the answer.
Well I answered my own question. I missed the database in this line dbo.excluded_Plaintiffs. Should be written newCityCollection.dbo.excluded_Plaintiffs.