I just want to concat two columns with seperator '-'.
These are the two columns, want to concat.
I am using this query to concat them
select concat(amt,endamt)as amount from mstcatrule
and it is giving me result this
But I Want that data of 2 columns should be sepearted by '-'
RESULT I WANT IS :
AMOUNT
0-0
100-99999999999
100-500
Alternative:
select amt || '-' || endamt as amount from mstcatrule;
Do it with two concats:
select concat(concat(amt, '-'), endamt) as amount from mstcatrule;
concat(amt,'-') concatenates the amt with the dash and the resulting string is concatenated with endamt.
Another way is to use double pipe.
select amt || '-' || endamt as amount from mstcatrule;
You may have to convert amt and endamt to varchar
In oracle this works for me! :D
select amt||'-'||endamt as amount from mstcatrule
Alternative you can use under query
select concat(amt,'-',endamt) as amount from mstcatrule;
A generic format for the query
Select concat(column1,'-',column2) as concatedCols from table_Name
For Postgresql only
Related
I have a string that contains ID numbers, something like this: „1;3;5;6;7;“
I want to select all rows in an SQLite table that have an ID which is contained in that string.
One select statement that gives me the rows 1,3,5,6 and 7.
Any idea how to do this?
You can do it with LIKE operator:
select * from tablename
where ';' || '1;3;5;6;7' || ';' like '%;' || id || ';%'
You can use the SQLite instr core function
SELECT * FROM your_table WHERE instr(';'||'1;3;5;6;7;',';'||id||';');
preceding the list with ; and wrapping the id in ;'s ensures that only the specific values are extracted (e.g. so that 1 doesn't get 11 111 etc)
I'm using this code:
SELECT *
FROM TableName
WHERE (ColumnName >= '' AND ColumnName < '豈')
OR (ColumnName >= '' AND ColumnName < '')
OR (ColumnName >= '' AND ColumnName < '');
from this answer - but it only returns entries that begin with anything in those ranges.
I need to be able to find entries that don't begin with characters in those ranges but contain characters that exist in the above ranges.
I have tried changing
'' AND ColumnName < '豈'
to
'%""%' AND CHS < '%"豈"%'
hoping that would work - but it evidently doesn't work like that.
How can I get this to work?
For single characters, you could use LIKE, but character ranges require GLOB:
SELECT ...
FROM MyTable
WHERE ColumnName GLOB '*[-豈]*'
OR ColumnName GLOB '*[-]*'
OR ColumnName GLOB '*[-]*';
The only way to do this with standard SQL would be to include an OR clause for each and every character within your ranges:
SELECT * FROM Table WHERE
ColName LIKE '%X%' OR
ColName LIKE '%Y%' OR
ColName LIKE '%Z%' . . .
which is tedious and probably not practical depending on how many characters are in your ranges.
Two other options you can look at are regular expressions, represented in SQLite with the REGEXP operator:
SELECT * FROM Table WHERE ColName REGEXP 'regular_expression'
or else full text search, documented here: http://www.sqlite.org/fts3.html.
I have a problem with the following query :
SELECT DISTINCT city || strftime("%Y", begintime) FROM Texts_original1
The query itself works but results themselves are concatenated so instead of for example :
city = Dublin
strftime("%Y", begintime) = 2008
I get :
city || strftime("%Y", begintime) = Dublin2008
Any ideas how to avoid that concatenation and make the response be separated to different columns ?
The || operator is "concatenate" - it joins together the two strings of its operands. (Source)
So, whatever it is you're trying to do, the || operator isn't what you want.
change || by a comma to make it different columns. what happens if you try to execute this?
SELECT DISTINCT city, strftime("%Y", begintime)
FROM Texts_original1
you tried to mention this: how to avoid that concatenation and make the response be separated to different columns
i simply have two fields. dtStartTime and dtStartDate.
I want to do a query now which returns one combined field dtStart using SQLite
I have tried
SELECT (dtStartDate+dtStartTime) as dtStart1, from ...
but it returns wrong values...
Thank you, shorty
PS: Dates are stored as unixepoch
SELECT datetime(d, t)
FROM (
SELECT date('now') as d, time('now') as t) as dt;
probably:
SELECT DATETIME(DATE(dtStartDate) || ' ' || TIME(dtStartTime)) FROM YourTable;
In short: I need to calculate the ending datetime given starting time and length in minutes.
I have a table with columns StartTime (type datetime) and LengthMinutes (type int). To calculate the ending time I would need some sql like this:
select datetime(StartTime, '+LengthMinutes minutes') from my_table;
How do I refer to the column LengthMinutes from within the modifier?
Edited: solved using dan04's suggestion. Thanks!
SELECT datetime(StartTime, '+' || LengthMinutes || ' minutes') FROM my_table;
select datetime(strftime('%s',StartTime)+lengthMinutes*60,'unixepoch') from my_table;