SQL Server : how to delete specific rows data with where condition in column? - sql

I have a table with some columns and rows. I want to delete some rows contain specific data at specific row.
Ex: the table name is EXAM
I want to delete row 1 and row 3 when input condition string is C.
I did with the statement:
DELETE FROM EXAM
WHERE Comumn2 = 'C'
but only deleted Row 3.

To match rows which contain a specific value, use LIKE instead of =:
DELETE FROM EXAM WHERE Column2 LIKE '%C%'

Another Way of doing it by using CharIndex
DELETE FROM EXAM WHERE CHARINDEX('C',Column2)>0

Related

SQL Join Problem Table two has more as one Record for ID

I have a SQL query problem.
i have two tables.
Table One UINT ID and same Fields
Table Two have Records with ID from the first Table. but more than one record for the ID.
Table Two:
ID=1 StringField1= "Hello" Stringfield2="World"
ID=1 StringField1= "Auto" Stringfield2="Street"
Is there a way to construct a query in such a way that I get a record of the form
1,Hello,World,Auto,Street,....etc.
Lot of Thanks.
Winfried
Have you a solution for this Problem?
Hello.
In Table 1 as the main Table is the field C_URI. This Field is the Key for the Table 2 , Field FK_Workitem. In Table 1 is one Record for the Key.
In Table 2 are the Costumer Fields with teh Fieldname and Feild value. in our Example:
Field 1 -> Name variationType value -> mandfeature
Field2 -> Name swe1_coverage value -> started
I now want to make a query in which I only have one record
C_URI, variationType value, swi_coverage value.
What must i do?
Select Statement
Output

There are multiple column in my table and I want to skip one column if value is null for that one particular column in oracle update query?

There are multiple column in my table and I want to skip one column if value is null for that one particular column and all other columns should be updated with there respective value in oracle update query.
Is there any simple way to do this ?
Example:
Let me explain my problem with example:
I am using merge query like below :
merge into table_X on (condition )
WHEN MATCHED THEN
UPDATE SET COLUMN_1=VALUE1 , COLUMN_2=VALUE_2,........
WHEN NOT MATCHED THEN
INSERT ( COLUMN_1,COLUMN_2...) VALUES (VALUE_1,VALUE_2);
Now in update statement I want to skip the update for one column suppose COLUMN_2 if its value is null , but all other column should be updated . Basically I want to preserve the existing value when null is coming .

Insert a column from output of a query into already populated postgresql database without adding new rows

I have a table named comments_live which has 4 fields and some 24000 entries. I want to add another field which is the output of a select query. The query is like this:
INSERT INTO comments_live SELECT SUBSTR(record,1, POSITION(' ' IN record)) AS project_id FROM comments_live;
What this query is doing is it's appending the result of the SELECT query to the table. I want the 'project_id' field to be appended to the existing 24000 rows. i.e. The above query should not add those extra rows to the table.
Any help would be appreciated.
PS: I tried adding a empty column 'project_id' to the table first and then executing the query, still I'm getting the same result.
I conclude from your code example that you want to add a column whose content is the substring from the column RECORD. If you succeeded in adding the empty column, then you just need code like the following:
update comments_live
set project_id=substr(record,1,[...])

Compare two column and fetch data from another column in same table

I want to compare Column A and Column C. And want to fetch data from Column B. All are in same table.But when I searched with 'C' column data I found diferent date. I need that date.
select b from table where a=c;
in this case a and c columns having the same data type. i.e character varying
Try this
Select date(b) from table name where a=c
As per you data it will return the null output
All columns in the table were value except column c
But you are indicated column c return date. Check it

data updation of a column in sql table based on another column of same table

i have 2 table with four & five column in sql
in 1st table four column like ID - Parant - Position - Assign Id (ID+Position)
in 2nd table five column like assign ID - ID - L1- L2- L3
assign id & ID automatic update from 1st table
L1,L2,L3 based on assign id & ID column
i want a query for L1 column for update data like this procedure
find (ID+Left) in assign Id column and if match with records then copy record from ID column whose matched in assign Id and paste in L1 column
plz help me
You can use update with join to update table column.
Example: http://sqlfiddle.com/#!2/07622