concatenating fields with no line break in SSRS - sql

I want to concatenate couple fields into one line using expression in SSRS
=Fields!Address1.Value & Fields!Address2.Value +" " + Fields!City.Value + " " + Fields!State.Value
But all the fields have a line break. It is driving me nuts. I need to get rid of the line break.
I also tried this in my query:
Concat(loc.Address1, loc.Address2,loc.City, loc.State) AS FullAddress
Still won't work.

Use this in your expression:
This is to replace char(10) (also known as vblf line break) with empty string "". It should get you the result.
Replace(Fields!Address1.Value & Fields!Address2.Value +" " + Fields!City.Value + " " + Fields!State.Value),char(10),"")

Perhaps you have char(13) and/or char(10) in your data.
Replace(Replace(Concat(loc.Address1,' ',loc.Address2,' ',loc.City,', ',loc.State),char(10),''),char(13),'') AS FullAddress

Related

How to remove " " (quote marks) from a string

I have two columns Block and Lot with some records having " " at the start and end of the number. I would like to remove the " " from the number for a report I'm writing.
There is also a space at the end of the number before the second ", for example "1234 " to 1234.
In case the characters you want to strip aren't always a space and double-quote, you could use series of REPLACE statements to remove those characters wherever they are.
UPDATE tbl set [Block] = replace(replace([Block],'"',''),' ',''),
[Lot] = replace(replace([Lot],'"',''),' ','')
Considering you want to remove both trailing/leading double quotes and spaces, I would use TRIM. With a literal, that would be this:
SELECT TRIM(' "' FROM '"1234 "');
db<>fiddle
Note, this is only available on SQL Server 2017+.

SQL Union not working when one table is empty

Hi I am trying to read data from different tables with a SELECT statement and want to use UNION to get one dataset in the end. It is possible that one table does not (yet) contain data. In this case I can read the data from the first two successfully but once I use UNION to combine it with the data from the empty table the resulting dataset will be empty as well, even though it contained data from the first two datasets before.
My problem is, data is shifted between these tables irregularily so there is no way for me to know in which of the three tables I will find the data and in any case usually I have to combine results from more than one table to get the entire dataset I need (one contains data only 3 months back, the other two contain data for the last and the current year - depending on the period I need the data for it is possible that I have to look in all the three of them to collect all the data I need).
Do you know how I can check out all three tables and read data to collect the entire dataset I need?
I also tested if everything works in case all the three tables contain data, et voila it worked and I retrieved all the data I needed. So the statement itself should be OK, just not applicable to the special case where one table does not contain data.
I am using Python to connect to the database and retrieve the data via an sql statement.
So my sql statement currently looks like this:
sql_stmt = (
"select " + sql_param+" from " + db_table +
" where datum>=" + season_start_sql + " and datum<" + season_end_sql +
" and statnr="+str(statnr) +
" union" +
" select " + sql_param+" from " + db_table +
" where datum=" + season_end_sql + " and stdmin<=" + season_end_time_sql +
" and statnr="+str(statnr) +
" union" +
" select " + sql_param + " from " + db_table + "_" + str(season_start.year) +
" where datum>=" + season_start_sql + " and datum<" + season_end_sql +
" and statnr=" + str(statnr) +
" union" +
" select " + sql_param + " from " + db_table + "_" + str(season_start.year) +
" where datum=" + season_end_sql + " and stdmin<=" + season_end_time_sql +
" and statnr=" + str(statnr) +
" union" +
" select " + sql_param + " from " + db_table + "_" + str(next_year) +
" where datum>=" + season_start_sql + " and datum<" + season_end_sql +
" and statnr=" + str(statnr) +
" union" +
" select " + sql_param + " from " + db_table + "_" + str(next_year) +
" where datum=" + season_end_sql + " and stdmin<=" + season_end_time_sql +
" and statnr=" + str(statnr) +
" order by datumsec")
This statement is simply untrue:
once I use UNION to combine it with the data from the empty table the resulting dataset will be empty as well, even though it contained data from the first two datasets before.
If one of the components of a UNION is empty, then you will still get the results from the other tables.
Note: If one of the tables does not exist -- which is quite different from being empty -- then the query returns an error, but not an empty result.
I will note that in general you should be using UNION ALL instead of UNION, to avoid the overhead of removing duplicate values. And your code is wide open to SQL injection attacks and to unexpected syntax errors. I would question whether your application can be designed so you don't have to use dynamic SQL for this purpose.

SAP IRPA Desktop Studio ctx.outlook.search filter E-mails by Date will not Work

I am trying to identify e-mails dynamically based on the current date.
I am having troubles putting the variable inside the statement:
Below on line 2 I try to concatenate PRDatafromProvider text with date which I set earlier. Perhaps the syntax is wrong. I set the date variable correctly and it logs fine.
ctx.outlook.mail.search({
filter : "\"" + "urn:schemas:httpmail:subject" + "\"" + "= 'PRDatafromProvider'" + date + " AND
" + "\"" + "urn:schemas:httpmail:read" + "\"" + "= 0",
//"urn:schemas:httpmail:date" + "\"" + "= '20200610'",
maxRow : 10,
dontThrowExceptionIfNoMailFound: true
});
Another question is the 4th line above, I comment it out because the code works fine without it but when I put that line back it will not executed and break the search method. This is why I am trying to put it in subject so that I can somehow go around it...
I am usually active online: if I missed any details, I can provide them quickly.

Access: Runtime error 3075 (missing operator) in SQL update query

First time using Access and wanted to make an update query that uses a variable for its table name. Now, I've gotten myself into a web of nothing good. When I get to the part the SQL code is needed for, I get Runtime error 3075 - Missing operator in '(((" + enteredid + ".todayDate)=Format(Now()','""Short Date"")))' I've never coded in SQL, so I have no clue what operators are needed.
My code:
strSQL = "UPDATE " + enteredid + " SET " + enteredid + ".signIn = Format(Now(),""Short Time"") WHERE (((" + enteredid + ".todayDate)=Format(Now()','""Short Date"")));"
My suggestions:
You can avoid the whole Format() issue in the WHERE clause by using the Date() function instead of trying to extract just the date part of Now().
Since you are doing an UPDATE on a single table you can just use the field (column) names without the TableName. prefix.
To make your code more robust, enclose the table name in square brackets so it won't crash if the table name contains spaces or other "funny" characters.
So, the revised code would look more like this:
strSQL = _
"UPDATE [" + enteredid + "] SET " + _
"signIn = Format(Now(),""Short Time"") " + _
"WHERE todayDate = Date()"

DELETE FROM table WHERE var = value does not remove entries

So I fetched some data from a mdb file in c# via
"SELECT * FROM " + listBox1.GetItemText(listBox1.SelectedItem) + " WHERE Note = '" + listBox2.GetItemText(listBox2.SelectedItem).Replace("'","\'") + "'";
which selects the right data, here it is
SELECT * FROM Main WHERE Note ='Hello'
The mdb data structure looks like this being plotted as a CSV-file:
"Record ID";Status;Placement;Private;Category;Note;Blob
14341665;4;2147483647;True;3;"""Hello"" - Neues
But when I try to remove entries with
"DELETE FROM " + listBox1.GetItemText(listBox1.SelectedItem) + " WHERE \"Record ID\" LIKE '" + dr[0] + "';";
or
"DELETE FROM " + listBox1.GetItemText(listBox1.SelectedItem) + " WHERE \"Record ID\" = '" + dr[0] + "';";
which looks like for instance
DELETE FROM Main WHERE "Record ID" LIKE '14341665';
The entries just stay there. I can rerun the select command even restart my application, the mdb is not changed.
Is record ID a numeric field? If so, lose the quotes.
DELETE FROM Main WHERE [Record ID] = 14341665;
Note that spaces in field (column) names will always be a problem. Such columns names have to be enclosed in square brackets, as do columns named with reserved words.
The record id is numeric, so don't put apostrophes around it:
"DELETE FROM " + listBox1.GetItemText(listBox1.SelectedItem) + " WHERE \"Record ID\" = " + dr[0]
Note: You should avoid using select * in production code, you should specify the data that you want returned. Also, you should use parameterised queries instead of concatenating values into the query.
if i remember correctly, "like" only works on string data, please check the data type of Record ID.
If Record ID is numeric, you may want to use database's conversion function to convert it into string before filtering using "like".
btw, remember to make sure that dr[0] is properly escaped.