Mysql update query set username ='tester' and phone ='12345' where id =1 - sql-update

Sometime, I make a mistake that use and instead of comma, what will be the result of it?
update table set username ='tester' and phone ='12345' where id =1

in case your query is
update `table` set username ='tester' and phone ='12345' where id =1
then it will perform an 'AND' operation on your data in username and phone columns and will return a result as 0 or 1 and it will set that result into your table username column
you can try this by running these queries in your mySQL
SELECT 'test' AND '1223'
SELECT '1234' AND '1223'
where output of first query is 0 because they are different and the output of second query is 1 read this to understand AND

update table set username ='tester' and phone ='12345' where id =1
this is not the correct syntax to write an update query this will generate an error because TABLE is a key word in SQL do you mean
update `table` set username ='tester' and phone ='12345' where id =1
UPDATE syntax is
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
as you can see that
UPDATE then table_name
SET then ColumnName = value , ColumnName = value.....
WHERE then Any Condition

Related

In Vtiger database where can i find the relation between tables vtiger_users and vtiger_contactdetails?

I want to know contact's owner with a MySQL query.
I'm using Vtiger 7.1 with PHP 7 and MySQL 5.
The owner information is stored in the smownerid column of the vtiger_crmentity table. The contactid column for vtiger_contactdetails table is a foreign key for the crmid column in the vtiger_crmentity table.
For example, given a contact with record id = 1000, you will use the query as -
select * from vtiger_users where id=(select smownerid from vtiger_crmentity where crmid=1000)

I am trying to write a script to update the column values if they are null with incremental values if the column id is the same

I am trying to write a SQL script to set the column values with incremental values based on the values of the id of the previous column. If the Job Id column is the same I would like the Employee column to be populated with incremental values.
I have this so far, but I'm not sure how to group it by JobID and reset the counter if they JobID changes:
DECLARE #employee INT
SET #employee = 0
UPDATE dbo.JobEmployees
SET Employees= #employees, #employees = #employees + 1 where Employees is null

Choose random column value between rows with same ID

I'm a beginner with SQL and I have to do a saved query in Informatica Cloud for a connection with a SQL Server database.
I have a table where the rows with the same formId have the same columns except "possibleSalesman", which is a text column:
formId, email, possibleSalesman
1, email1, user1
1, email1, user2
1, email1, user4
2, email2, user2
3, email3, user3
3, email3, user1
What I need, is to get one row for each id and pick "possibleSalesman" randomly.
For example:
1, email1, user4
2, email2, user2
3, email3, user3
I found kind of a similar question but the solution wouldn't help me because there are a few restrictions in Informatica:
Only SELECT statements
Can't use asterisk to select all columns
Can't use conversion functions
Can't use COUNT function
If someone could help me I would be very grateful!
SELECT
FormId
,Email
,possibleSalesMan
FROM
(
SELECT
FormId
,Email
,possibleSalesMan
,ROW_NUMBER() OVER (PARTITION BY FormId ORDER BY NEWID()) AS RowNumber
FROM
TableName) t
WHERE
t.RowNumber = 1
In SQL Server 2008+ you can use the ROW_NUMBER() window function and NEWID() to achieve a random order and then select the result where ROW_NUMBER() = 1.

UFT API TEST: Create SQL query based on values from previous step activity at run time

Steps to be performed in UFT API Test:
Get JSON RESPONSE from added REST activity in test flow
Add Open DB connection activity
Add Select Data activity with query string
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = ' 1234'
(here COL2 value has length of 7 characters including spaces)
In the above query values in where clause is received(dynamically at run time) from JSON response.
When i try to link the query value using link to data source with custom expression
eg:
SELECT COUNT(*) FROM Table1 Where COL1 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL1}' and COL2 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL2}'
then the QUERY changed (excluding spaces in COL2) to:
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = '1234'
I eventried with concatenate and Replace string activity but same happens.
Please kindly help..
You can use the StringConcatenation action, to build de Query String.
Use the String as Query in Database "Select data"

How to Update a single column through informatica?

I have a target table with the following attributes:
PARTY_ID PK
START_DATE PK
STATUS_CD PK
END_DATE
I have a dynamic lookup which is returning me 1(insert) 2(update) 0 (duplicate) for each row from source table.
What i want is when i get 2(update) to add an END_DATE to the updated row without changing anything else.
For example i have the following row in my target table:
1 12/01/2014 2 NULL
and i get this row from my source table:
1 14/01/2014 6 NULL
What i want is to add ONLY the end date to the target table without anything else. LIKE:
1 12/01/2014 2 14/01/2014
I know how to update the whole row but i dont know how to update only one column.
Schema:
CREATE SET TABLE IND_MAR_STATUS ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
INDIVIDUAL_PARTY_ID DECIMAL(18,0) NOT NULL,
INDIV_MARITAL_STAT_START_DTTM DATE FORMAT 'YYYY-MM-DD' NOT NULL,
MARITAL_STATUS_CD VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
INDIV_MARITAL_STAT_END_DTTM DATE FORMAT 'YYYY-MM-DD',
ETL_SOURCE_ID DECIMAL(18,0) NOT NULL,
ETL_EXTRACT_SPEC_ID DECIMAL(18,0),
ETL_JOB_RUN_ID DECIMAL(18,0))
PRIMARY INDEX ( INDIVIDUAL_PARTY_ID );
Simply disconnect the target ports you don't want to update (i.e. only PARTY_ID and END_DATE should be connected).