how do i divide 2 varchar2 columns? [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Need to divide 2 varchar columns
tried cast function to convert varchar to number

I have put sample below for SQL Server. I am explicitly casting both dividend(10 below) & divisor (2 below) for clarity in the programming.
DECLARE #value1 VARCHAR(10) = '10'
DECLARE #value2 VARCHAR(10) = '2'
SELECT CAST(#Value1 AS INT) / CAST(#Value2 AS INT)

Related

Split Word into sentence using SQL Server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have a column called Test for saving the char eg.
A:Hi B:13/06/2022 C:Peter
How to split the data of Test column to look like this:
test
A:Hi C:Peter B:13/06/2022
I want to try adding a newline to the B data using CHAR(13) + CHAR(10) but how do I split the B data in the test column and then add a newline using CHAR(13) + CHAR(10). Thanks
If you are using SQL Server you can use string_split() to extract the B. Assuming that you have space in between.
declare #test varchar(100) = 'A:Hi B:13/06/2022 C:Peter'
select * from string_split(#test,' ')
where [value] like 'B%'

How to find particular string value for the particular group ID in a table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
There is EIID column with different strings value grouped and string column contains JPNaOn , PDSCLm , PDSCLs data values .
Please help me to filter the elID which contains only a particular value 'PDSCLm' and doesnot contains JPNaOn and PDSCLs column data for the particular EIID .
Is this what you are looking for?
SELECT EIID
FROM UserTable AS t
WHERE strings = 'PDSCLm'
AND NOT EXISTS (
SELECT 1
FROM UserTable AS t2
WHERE t.EIID = t2.EEID
AND t2.strings IN ('JPNaOn', 'PDSCLs')
);

Add character to end of field in SQL Database if condition = true? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to add a star * to the end of the 'DisplayName' field of any record with a category of 2. Not sure how to do this but I think this is on the right track?
UPDATE `table_name`
SET `DisplayName` = replace(DisplayName, 'old_text', 'new_text')
WHERE Category = '2';
My problem is I need to just add a space and a character at the end, not do a find and replace.
The generic SQL would be:
UPDATE `table_name`
SET `DisplayName` = CONCAT(DisplayName, '*')
WHERE Category = '2';
CONCAT() can be spelled in different ways depending on the database -- such as + or ||.

How to replace only 3rd character of employee name with * in SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to replace only 3rd character of employee name with * in SQL.
On SQL Server you can use this:
SELECT STUFF(N'Employee',3,1,N'*')
On MySQL
SELECT INSERT(N'Employee',3,1,N'*')
ANSI SQL way:
SUBSTRING(employee from 1 for 2) || '*' || SUBSTRING(employee from 4)
Alternatively PASTE is used by some dbms products:
PASTE(employee,3,1,'*')

Oracle SQL check empty and return value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can you please help to write a query with the below.
I want to check the two columns Date and Description to check if empty/null, if both column value is empty/null return a value as YES.
COLUMN_NAME DATATYPE NULLABLE
Date Date Yes
Description Varchar2(100) Yes
Please help
SELECT other_column1, other_column2
, CASE WHEN "DATE" IS NULL AND description IS NULL THEN 'Yes' ELSE 'No' END AS both_columns_null
FROM mytable
The column named DATE is in double quotes because "DATE" is a reserved word in Oracle.