SQLbase data not numeric - sql

I have a query that runs in Excel, that will need to show data from an SQLbase database where I only have read-access. I cannot modify the database in any way. The column I need to be able to filter on is a varchar column, but it's values are only numbers. I need to be able to filter with between in Excel, so I've tried to do column + 0 so Excel picks it up as a number. This worked before, but now it fails on some numbers.
The number 704977990024 works, but 991098000265 doesn't. With the second one I get Data is not numeric.
This is the query:
SELECT (TABLE1.COLUMN + 0) AS "Artikelnummer"
FROM DB.TABLE TABLE1
LEFT JOIN DB.OTHERTABLE TABLE2
ON TABLE1.COLUMN = TABLE2.COLUMN
How can I make sure I get it as a number in Excel? If not in the query, then how in Excel itself? When I set the column to number in excel, it still displays as text and will not be numeric unless I try to edit the cell.

It's probably overflowing. An alternate way to get what you need Is to pad the numbers with leading zeroes. This will avoid the overflow and let you use a range. I don't know the syntax... something like where Right('000000000000000' + nu, 17) between ....

I have not found a solution to this, but I did find a manual workaround.
You select the whole column and cut&paste is somewhere else. You cut it because the colum needs to be empty when putting the data back. After that, you select your newly created column, and copy or cut it. Then you select the column where the data needs to be (the one you just emptied), and press paste > paste special. Then you select multiply (or any other) and press ok. That way the columns will be numeric.
It might be a manual thing, but it was the one solution I've found to this problem.

Related

T-SQL selecting all col to update in merge

Maybe that stupid question, but I don't know how to describe my problem to uncle google.
I have two simple tables with 3 rows: ID, Name, SomeVal;
Now I want update them with merge, and that's simple:
MERGE Locations T
USING Locations_2 S ON T.ID=S.ID
WHEN MATCHED THEN
UPDATE
SET
T.Name=S.Name,
T.SomeVal=S.SomeVal;
Ok, that works, but I wrote every column name by hand. So, when I want to update for example table with 30 columns, writing everything by hand will be painful. So, is there any option to update every column in the table no matter how many columns it has?
I tried "*". It is UPDATE SET T.*=S.*, and that didn't work.
What I normally do when I want to be time efficient (or lazy, depending on your view) is this:
Run this command:
sp_help TableName;
Copy/paste the first column, then hold down Alt whilst dragging the mouse cursor in front of the column names. This way I can then type one comma in front of all the fields. Then I do the same after the field name except with an = sign.
That's the only shortcut I can think to help you, and has saved me hours of typing over the years.
No. Merge statements are very verbose. You can hack a shortcut by scripting your table as CREATE, copy the column names using SHIFT + ALT to select a large swath of them, then paste them into the MERGE query, hit space, add the = sign, then paste again.
The statement is one direction, (i.e., you can't update S with T; only T can be updated) so you don't strictly need to provide the source/destination alias for each column.

Postgres - split number and letter doesnt fill column

I have received help for splitting a column wit nr and letter.
In the SQL script it all works perfect. It runs complete, with no errors.
But the columns itself doesn't get filled.
I have tried to create te columns in advance as text or as integer. But it doesn't get filled. The SQL query it self turn out ok. But in reality it stay empty. What is wrong?
Your question is not completely clear, but it sounds like what you are trying to do is take a value from one column of a table, split it and use the result to update two other columns in the same table.
If that is the case, you would want to be using the SQL UPDATE command instead of SELECT.
UPDATE d1_plz_whatever
SET nr=SUBSTRING(hn FROM '^[0-9]+'),
zusatz =SUBSTRING(hn FROM '[a-zA-Z]+$');

extract data in exel sheet using macro

you most probably going to think "what an idiot" but remember i never done any type of coding before so this is all new to me,
My problem are that i'm working on a HUGE excel sheet with loads of data that is not needed. i need to sort the data into a few columns, i only need column "A,K,AN,AQ" but in column "AS" i only need certain values (yes,no,blank) i only want the yes and blank values. like i said never done any coding before but i know that you can use an macro to do it so please help, how do i go about this?
before trying to get into macros, try to use functions with if else statements. They are quite easy to handle. Like: If (yes) then put it into X. Later, you could select all needed. Also, check the, how the dollar sign is used
use this links to see, if it is something for you.
One quick and dirty way of getting this job done would be to:
Delete the columns you don't need.
Select all cells in the range you're interested in, click the Insert menu, and choose "Table". If your columns have titles, select the box for "My Table has Headers."
-This turns your data into an array so that Excel recognizes that each row is an entry (instead of thinking that the cells are unrelated).
Now you can use the filter icon in the column headers to select and display only the rows containing the values in column X that you're interested in.
Note that there are some limitations to what the table feature is good for, so, as always, whether this is a good solution for you depends on what you want to do with the data.

SQL Server - Insert Blank Rows after row

I have a query for SQL server (2014). This query is then processed by my application that exports the result set to excel.
I have been asked if I can add space underneath each row, as the spreadsheet will be printed and they would like to make notes on it.
I have tried adding carriage returns to my query to try and stretch out the height of the column so
(CHAR(13)+CHAR(13)+CHAR(13)) as 'Blank Column'
But excel didn't pick up the returns.
The only other thing I can think of is to add 4-5 blank rows after each row with data, I'm just not sure how to do that, or even if it's possible
Try something like this:
SELECT REPLICATE(CHAR(10),5) AS [Blank Column]

Date in a short text data type field... Select query trouble

In my Access database, I have a table called customers. In this table I have a column called DateEntered. The data type for the field is short text.
The values in this column are not coherent - they come in several variations:
MM-DD-YYYY,
MMDDYYYY and
MM/DD/YYYY.
There doesn't seem to be any standard set.
My goal is to select all customers from 2012. I tried
select *
from customers
where DateEntered <('%2013') AND >('%2012');
but it comes up blank when I run it.
Can anyone point out what I'm failing to do correctly & more importantly explain why exactly this query doesn't work in Access? From my understanding of SQL (not very advanced) this should work.
Another variant)
select * from customers where RIGHT(DateEntered, 4) = '2012'
If you have control over the database and application code, the best way to handle this is to use an actual Date field instead of text in the table.
One way to handle this would be to add a new field to the table, write a query or two to correctly convert the text values to actual date values, and populate the new field.
At this point, you would then need to hunt down the application code the refers to this field in any way and adjust to treat the field as a date, not text. This includes your insert and update statements, report code, etc.
Finally, as a last step, I would rename the original text field (or remove it altogether) and rename the new date field to the original field name.
Once you fix the problem, querying against the field will be a piece of cake.
Alternatively, if you can't alter the table and source code, you can use the date conversion function CDATE() to convert the text value to an actual date. Note that you may need to guard against non-date entries (NULL or empty string values, as well as other text values that aren't really dates in the first place). The IsDate() function can be your friend here.
If you have the time and patience, fixing the data and code is the better approach to take, but sometimes this isn't always feasible.
Why don't you use LIKE operators (they're appropriate when you have a pattern using % and _):
select * from customers where DateEntered like '%2013' or DateEntered like '%2012'