Derby database appending space when returning values - sql

Using a Derby Database:
In my addresses table, I have address information, with a column for the zip code of type varchar(45).
If I query (select * from addresses where address_id = 1234) and look at the ZIP Column, it returns '95035'.
If I query (select ZIP from addresses where address_id = 1234) it returns '95035 ' (With a space at the end).
I noticed this on the zip column because I have a basic validator running on the addresses and it checks for extra spaces in the zip code, so I don't know how widespread this issue is for other columns and tables. Less than .02% of my rows are being affected by this, and if I delete the row and re-enter it with the same data it fixes the problem.
Can anyone tell me why this would be happening/how to fix it?

Related

Update string rows by substring patterns sql

Got a apparently simple problem resolvable.
I want to update emails in my sql table with one query.
All emails ending by #notgoodexample.com (knowing I have several pattern that my email will match)
Should after that query be #goodexample.com
And I need to keep what is before the '#'.
My best try for the moment is
Update tableName SET table.email_addresse = concat(table.name, table.lastname, '#goodexample.com' --cheating a little bit cause these addresses are name.lastname#
WHERE email_address LIKE '%pattern%'
OR email_address LIKE '%pattern2%'
Do you have any tips for me ?

Email address as a Table in SQL

I'm just wondering if it is OK to used the email address as a Table in SQL script? for example,
abcd_activity#cdf.com up
select distinct usr.user_name as USER_NAME, usr.id as USER_ID
from abcd#cdf.com usr, abcd_activity#cdf.com -- <-----------------------
where usr.id = ua.id
group by usr.name, usr.id;
My problem is that, I received the log file containing the error of the script and I noticed that the table used is email address. So, my assumption is that the caused of the error is in the table itself. Or, is it OK to use an email address as a lookup table in script?
This is a bit long for a comment.
No, it is not all right to have a table name like abcd_activity#cdf.com, for the simple reason that . and # are not allowed as table names. So, any attempt to do:
from abcd_activity#cdf.com
is going to result in a syntax error.
SQL does allow you to escape table names. You can get around this problem with one of these:
from "abcd_activity#cdf.com"
from `abcd_activity#cdf.com`
from [abcd_activity#cdf.com]
(which depends on your database).
More importantly, though, is that there is no sensible reason (that I can think of) to have a table represent separate emails. Normally, email would be a column in a table, not a table name.
So, you would have tables like:
Users Table
userId userName email . . .
And UsersActivity table:
userActivityId userId . . . .
email would be a column in Users, which you would look up using a JOIN.

split string with specific character

Here is my situation
there is a column that comes from csv file, i loaded all fields properly in sql but in email column, i have more than 1 email address for some records.
if it would be 2 emails, i could handle but as long as i have 3-4 or more emails, then i have little problem.
here is an example
'ekuntsche#addictionsuisse.ch;ekuntsche#suchtschweiz.ch;ekuntsche#sfa-ispa.ch;ekuntsche#addiction-info.ch'
this is only 1 column, i need to split them to 4 different column as email1,email2,email3,email4 and delimiter is ';'
I think i should use charindex and substring etc. but i could not create it.
if someone can create a function and show how to run the function, that would be super helpful.
thank you
database name 'bi_deploy'
main column name is 'email'
unique id for this table is 'ID'
(this is only email table, every row will have 1 email address, i can make it actually, but i could not split emails properly)

Find out if a value exists in a column with a large input values set

What is the most effective (and simple) way to find out if a specific column cells of a table contain one of a given values?
To give you some background, I have a list of 1000 ID numbers. They might or might not exist in a "FileName" column of a table "ProcessedFiles" as a part of the filename.
Basically, I need to check which of these 1000 tasks have been processed (i.e. they exist in the table).
The thing that I came with seems very uneffective:
SELECT * FROM ProcessedFiles
WHERE FileName LIKE '%54332423%'
OR FileName LIKE '%234432%'
OR FileName LIKE '%342342%'
...
etc
Thanks for help!
You could create a temporary table and insert all the Ids in a column. Then you could cross join with the ProcessedFiles table and check for the id in the name with a like:
SELECT pf.*
FROM ProcessedFiles pf,table t
WHERE pf.FileName like '%'+t.Id+'%'
I tested the above and it worked on SQL Server.

Recordset returns the correct number of row but with all field empty

I have the same copy of access running in 3 cities right now. They work perfectly ok. They are 99% the same with one minor difference. Each of them has two views which use different odbc connection to different cities DB (all these databases are SQL Server 2005). The views act as datasource for some two very simple queries.
However, while I tried to make a new copy for a new city, I found that one of the simple internal query returns the correct number of row but all data are empty while the other query functions correctly.
I checked the data of these two views, the data is correct.
The one causing problem are like
Select * from View_Top where Name = "ABC"
when the recordset returns, even rs!Name give me an empty string.
Please help
Well the query looks a little wrong to me, try using ' instead of " to delimit your ABC string...
Without the definition of VIEW_TOP it's hard to tell where your error is, but if you're getting rows but the columns are NULL I'm guessing that VIEW_TOP (or something it depends on) includes an OUTER JOIN and you're pulling the columns from the wrong side of the JOIN.
SELECT
acc.FIRM,
acc.OFFICE,
acc.ACCOUNT,
a.CONV_CODE,
a.OTHER_AMT AS AMOUNT,
a.TRANS_DATE,
a.DESCRIPTN,
a.JRNAL_TYPE
FROM AccTrans AS a LEFT OUTER JOIN ACC AS acc ON a.ACCNT_CODE = acc.ACCNT_CODE
WHERE
(acc.SUN_DB = 'IF1') AND
(ANAL_T0 <> '') AND
(a.TRANS_DATE < '20091022') AND
(a.JRNAL_TYPE = 'MATCH');
This is the definition of the view. Indeed, in Access i am able to view the result of this query, it has data. that's why i know the recordset returns the correct number of row (by counting the loop in the code). sorry for my mistakes, i use Account in the where clause, the select statements should be like
select Firm, Office, Account, Trans_Date.... from
view_top
where account = 'ABC'
the query returns the right number of row but all row data (even the account field) are empty string.
then i found out what really cause the problem is the AMOUNT field, if i omit the amount, everything works. though i don't understand why.
view_top definition
"Name, Account, AccountCode, Amount, Date...."
Select Statements:
Select Name, Account, AccountCode, Amount, Date
From View_Top Where Name = 'xxx'
I found that if I omit the Amount, everything works.
Though I still don't understand why.