Split Word into sentence using SQL Server [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 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%'

Related

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 ||.

Dynamically Alter column datatype from nvarchar to decimal if a condition is satisfied 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
I would like to dynamically alter the data type of my column "ROE 2" in table tb1 to decimal if Column header is like "ROE ".
My column header will increase over time
Is it possible?
You can use the catalog view sys.columns to retrieve all your wanted columns from your table and construct an ALTER statement as a string:
SELECT 'ALTER TABLE tb1 ALTER COLUMN [' + name + '] Decimal(18,2) NULL'
FROM sys.columns
WHERE [object_id] = OBJECT_ID('tb1')
AND name LIKE 'ROE%'
From there you can grab the queries and run them manually or open a CUSROR and iterate each statement to run them with an EXEC call.
You need to write dynamic SQL for that..read it from here http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-2

How to extract only the rows using where clause and Like operator in SQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a column with data 0xxxx and 00xxx. How to extract only the rows of 0xxxx with second digit not being '0' using where clause and Like operator in SQL
You can use SQL wild cards to achieve your result.
SELECT * FROM yourTable WHERE yourColumn LIKE '0[!0]%';
Above, will fetch you results which starts with 0 but not followed by 0
You can get more information about the wild cards from here
Substring might do this for you :
Select * from Table where SUBSTRING(column1, 2, 1) <> '0'
For standard SQL syntax do
SELECT * from tableName
WHERE columnName NOT LIKE '00%'
You can use this
select * from table
where column_text
not like '00%'

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,'*')