SSRS - IIF/Switch/Replace multiple conditions in a field - reporting-services

Have a nvarchar column in ms sql that, based on user input, may or may not have a carriage return and a line break together (CHR(13)&CHR(10)), just a carriage return (CHR(13)), just a line break (CHR(10)). In using that column in ssrs, I need to find if any of the above exist and replace them with the string \x0D\x0A, \x0D, or \x0A respectively.
I'm getting lost in this expression, any help is appreciated.
=SWITCH
(
(InStr(Fields!Info.Value, CHR(13)&CHR(10) > 0, REPLACE(Fields!Info.Value, CHR(13)&CHR(10)), "\x0D\x0A")),
(InStr(Fields!Info.Value, CHR(13) > 0, REPLACE(Fields!Info.Value, CHR(13)), "\x0D")),
(InStr(Fields!Info.Value, CHR(10) > 0, REPLACE(Fields!Info.Value, CHR(10)), "\x0A"))
)
Error is:
System.Web.Services.Protocols.SoapException: The Value expression for
the textrun ‘Info.Paragraphs[0].TextRuns[0]’ contains an error:
[BC30455] Argument not specified for parameter 'Replacement' of
'Public Function Replace(Expression As String, Find As String,
Replacement As String, [Start As Integer = 1], [Count As Integer =
-1], [Compare As Microsoft.VisualBasic.CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary]) As String'. at
Microsoft.ReportingServices.Library.ReportingService2005Impl.SetReportDefinition(String
Report, Byte[] Definition, Guid batchId, Warning[]& Warnings) at
Microsoft.ReportingServices.Library.ReportingService2010Impl.SetItemDefinition(String
ItemPath, Byte[] Definition, String expectedItemTypeName, Property[]
Properties, Warning[]& Warnings) at
Microsoft.ReportingServices.WebServer.ReportingService2010.SetItemDefinition(String
ItemPath, Byte[] Definition, Property[] Properties, Warning[]&
Warnings)

Try this:
=SWITCH(
InStr(Fields!Info.Value, CHR(13) & CHR(10)) > 0,
REPLACE(Fields!Info.Value,CHR(13) & CHR(10), "\x0D\x0A"),
InStr(Fields!Info.Value,CHR(13)) > 0,
REPLACE(Fields!Info.Value, CHR(13), "\x0D"),
InStr(Fields!Info.Value, CHR(10)) > 0,
REPLACE(Fields!Info.Value, CHR(10), "\x0A")
)
Note if you use Switch function it will execute only the first case
that is true, so if the first condition is true the second and the
third will not be evaluated therefore not executed.
If you want to replace every char you should just use multiple REPLACE nested functions.
=Replace(
Replace(
REPLACE(Fields!Info.Value,CHR(13) & CHR(10), "\x0D\x0A"),
CHR(13),"\x0D"),
CHR(10),"\x0A")

Related

MySQL Entity Framework: Can't create index

I'm using MySql.Data.Entity version 6.10.8 with Entity Framework.
I'm doing "Code first" to let the MySql-provider create the database structure.
Whenever the migrations contains a creation of a Index my migration fails when running the update-database command. The error message and stack trace are as follows:
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options,
NumberFormatInfo numfmt) at System.Convert.ToDouble(String value)
at
MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(CreateIndexOperation
op) at
MySql.Data.Entity.MySqlMigrationSqlGenerator.<.ctor>b__22_4(MigrationOperation> op) at
MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(IEnumerable 1
migrationOperations, String providerManifestToken) at
System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList 1
operations, String migrationId) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId) at
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String
migrationId, VersionedModel targetModel, IEnumerable 1 operations,
IEnumerable 1 systemOperations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration
migration, DbMigration lastMigration) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration
migration, DbMigration lastMigration) at
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable 1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable 1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String
targetMigration) at
System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClasse.b__d()
at
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action
mustSucceedToKeepDatabase) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action
mustSucceedToKeepDatabase) at
System.Data.Entity.Migrations.DbMigrator.Update(String
targetMigration) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String
targetMigration) at
System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Input string was not in a correct format.
How to repeat:
Use Swedish Windows (or any other language which do not use "." as the decimal separator).
Create a migration file with an index, such as:
CreateTable(
"dbo.AspNetRoles",
c => new
{
Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
Name = c.String(nullable: false, maxLength: 256, storeType: "nvarchar"),
})
.PrimaryKey(t => t.Id)
.Index(t => t.Name, unique: true, name: "RoleNameIndex"); // This line causes the exception
Run database-update
(A bug report has been sent to MySql: https://bugs.mysql.com/bug.php?id=92561)
This error is due to MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op) which checks the version of the database by converting a string to double. However it does so without specifying an IFormatProvider. Since Swedish use "," as the decimal separator this conversion fails (the version number is separated by ".").
By overriding MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op) this can be avoided. Use the code from this answer https://stackoverflow.com/a/51756143/1037864 (which is an answer for a different question)

Having trouble getting MySQL data returned

I have a long Perl script that in other places returns MySQL table data successfully using binds:
$query2 = "SELECT tblExportFiles.CompID, CompEmail, export_id, export_name, query, num_records, sample_rate, record_startnum, Description, Pull_Type, remote_CompID FROM tblExportFiles INNER JOIN tblCustomers USING(CompID) WHERE done=0 ORDER BY export_id ASC ;";
$sqlQuery2 = $dbh->prepare( $query2 );
$sqlQuery2->execute or die "can't execute the query: " . $sqlQuery2->errstr;
$sqlQuery2->bind_columns(
\$CompID, \$CompEmail, \$export_id, \$fileName,
\$queryFile, \$numRecords, \$sampleRate, \$recStartNum,
\$description, \$qType, \$remote_CompID
);
while ( $sqlQuery2->fetch ) { ... }
But when I do the same sort of query here, it fails to return any values but doesn't throw an error:
my $ftpQuerySQL = "SELECT tblResellersData.http_address ,ftp_address, ftp_username, ftp_password, ftp_dir, http_name, tblResellerCustomers.CompEmail FROM tblResellersData, tblResellerCustomers WHERE tblResellerCustomers.User_ID = '$remote_CompID' AND tblResellersData.CompID = '$CompID' ; ";
print "FTP SQL = $ftpQuerySQL\n\n";
$QueryFTP = $dbh->prepare( $ftpQuerySQL );
$QueryFTP->execute() or die "can't execute the query: " . $QueryFTP->errstr;
$QueryFTP->bind_columns(
\$http_address, \$ftp_address, \$ftp_username, \$ftp_password,
\$ftp_dir, \$remote_name, \$CompEmail
);
$QueryFTP->fetch();
It throws warnings
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 302.
is a located in
Use of uninitialized value $ftp_dir in scalar chomp at ./Cron_file_output.pl line 303.
Use of uninitialized value $http_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_password in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $remote_name in concatenation (.) or string at ./Cron_file_output.pl line 304.
RETURNED VALUES......., , , , , , j#adki87.com
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 310.
But when I ran the same SQL under phpMyAdmin, it gave this result:
http_address website's url ftp_address ftp_username ftp_password ftp_dir http_name
http://www.highpeaksbyway.com/ highpeaksbyway.com data#highpeaksbyway.com dataUUU666##) pulls/ TEST ME
What are lines 302, 304, and 310?
It looks like your criteria (the WHERE conditions) are failing, and the statement returns no records
What does $QueryFTP->fetch return? You need to check its status before you use it. That is the major difference between the code that you think "works" and your problem case
You need to check the values of $CompID and $remote_CompID before the execute. You should also use placeholders in the prepare call, and supply the values in execute

Converting a MongoDB Query String with Datetime field into Dict in Python

I have a string as follows,
s= "query : {'$and': [{'$or': [{'Component': 'pfr'}, {'Component': 'ng-pfr'}, {'Component': 'common-flow-table'}, {'Component': 'media-mon'}]}, {'Submitted-on': {'$gte': datetime.datetime(2016, 2, 21, 0, 0)}}, {'Submitted-on': {'$lte': datetime.datetime(2016, 2, 28, 0, 0)}}]}
" which is a MongoDB query stored in a string.How to convert it into a Dict or JSON format in Python
Your format is not standard, so you need a hack to get it.
import json
s = " query : {'names' :['abc','xyz'],'location':'India'}"
key, value = s.strip().split(':', 1)
r = value.replace("'", '"')
data = {
key: json.loads(r)
}
From your comment: the datetime gives problems. Then I present to you the hack of hacks: the eval function.
import datetime
import json
s = " query : {'names' :['abc','xyz'],'location':'India'}"
key, value = s.strip().split(':', 1)
# we can leave out the replacing, single quotes is fine for eval
data = {
key: eval(value)
}
NB eval -especially on unsanitized input- is very unsafe.
NB: hacks will be broken, in the first case for example because a value or key contains a quote character.

Calling a string / object to a adodb connection

Hi all im having issues with this section of script;
linkString = "Info "
SQL_query ="INSERT INTO search (Title,Program,Open) VALUES ('"& txtTitle.value &"','"& txtProgram.value &"','"& linkString.value &"')"
I basically need the code to input the "linkString" value into the section of my SQL Query however any way I try I recieve either object errors or string errors if I attempt to set the value?
Thanks,
James
linkString is a string, not an object. So there is no linkString.value to concatenate. Just use plain linkString.
Update wrt comments:
Assuming the objects and their properties are decent, your concatenations - though disgusting - are correct. Evidence:
txtTitle_value = "AAA"
txtProgram_value = "BBB"
linkString = "CCC"
txtOpen_value = "111"
linkString = "Info"
WScript.Echo linkString
SQL_query ="INSERT INTO search (Title,Program,Open) VALUES ('"& txtTitle_value &"','"& txtProgram_value &"','"& linkString &"')"
WScript.Echo SQL_query
output:
cscript 26403056.vbs
<a href="#" onclick="TINY.box.show({iframe:'nodes/111',boxid:'frameless',width:750,height:450,fixed:false,mask
opacity:0})">Info</a>
INSERT INTO search (Title,Program,Open) VALUES ('AAA','BBB','<a href="#" onclick="TINY.box.show({iframe:'nodes
/111',boxid:'frameless',width:750,height:450,fixed:false,maskopacity:0})">Info</a>')
If you get "missing operator" errors you removed those operators yourself.
Update wrt comments II:
If you get an SQL error, escape the single quotes in linkString; check your SQL docs to learn how ('', \', ...).

Access VBA error with DCOUNT

Access is telling me the following is improper, but I can't see how.
cnt = DCount("recid", "dbo_HR_EmployeeTrainings", "EnteredDateTime > '" & CStr(DateAdd("Minute", -1, Date)) + "'")
Error given is Run-time error '5': Invalid procedure call or argument
That would be n, not minute.
See http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx
Why are your dates stored as strings?
Re comment try:
DCount("recid", "dbo_HR_EmployeeTrainings", "EnteredDateTime > DateAdd('n', -1, Date())")