Can't join and select in Sequel -- PG::SyntaxError [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 last month.
Improve this question
I'm trying to rename a column at join:
# ...............
result = DB[:my_items1].join(:my_items2, id: :my_item2_id).
select([Sequel[:my_items2][:name].as(:my_items_name),
Sequel[:my_items2][:amount].as(:my_item2_amount)
])
# ...............
Exception:
Sequel::DatabaseError - PG::SyntaxError: ERROR: syntax error at or near "AS"
LINE 1: SELECT ("my_items2"."name" AS "my_item2_name", "...
^
:

Dataset#select takes multiple arguments, not a single array:
result = DB[:my_items1].join(:my_items2, id: :my_item2_id).
select(Sequel[:my_items2][:name].as(:my_items_name),
Sequel[:my_items2][:amount].as(:my_item2_amount)
)

Related

How to replace original text after a specific word at oracle? [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 3 months ago.
Improve this question
I have a message about unique OTP message like below at DB. I want to replace 7466 with 7**6 without breaking other parts. I tried to use REGEX and INSTR but it does not work any suggestion about the solution?
OTP codes have to be unique so at any message, the part I want to change are different. OTP code should not always coincide with the same place.
I have also three different types of message. So I don't store the OTP code in the column. It just existing in the message columns.
SELECT id, SMS_TO_CUSTOMER FROM CTB.CTB_SMS_HISTORY
WHERE 1 = 1 AND id = '51684'
Original Text:
Do not share your password.You have a one password that is 7466 with tax
69.9$, .......
Expected Result:
Do not share your password.You have a one password that is 7**6 with tax
69.9$, ........
like so ;
Message1:
Do not share your password.You have a one password that is 6**6 with tax
0.01$, .........
Message2:
............, 6**6 you must enter the verification code .............
Message3:
6**6 ........... 0.05$ o.............
Use REPLACE:
SELECT id,
REPLACE(SMS_TO_CUSTOMER, ' 7466 ', ' 7**6 ') AS sms_to_customer
FROM CTB.CTB_SMS_HISTORY
WHERE id = '51684'
or, for a dynamic code passed in to the query via the :otpcode bind variable:
SELECT id,
REPLACE(
SMS_TO_CUSTOMER,
' ' || :otpcode || ' ',
' ' || SUBSTR(:otpcode, 1, 1)
|| LPAD('*', LENGTH(:otpcode) - 2, '*'
|| SUBSTR(:otpcode, -1, 1)
|| ' '
) AS sms_to_customer
FROM CTB.CTB_SMS_HISTORY
WHERE id = '51684'

update the sql table with some condition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to update my whole sql table except some rows. Is it possible?
I am trying with this query but not work.
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id`
!IN ('5','6','7')
It seems like you meant to use the not in operator:
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id` NOT IN ('5', '6', '7')
-- Here ------------^
Use NOT IN instead of !IN
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id`
NOT IN('5','6','7')
Yes it is possible :
Update 'boon_rize'.'users'
Set 'zip'='0'
Where 'users'.'id'
Not In ('5','6','7')
Good Luck.

ORDERBY 'Incorrect Syntax' in Declare Statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to do such a simple task, yet it's driving me crazy how it keeps failing.
DECLARE #neighbour HierarchyId = (SELECT [stPath] as tmpPath
FROM [DEV].[tmp].[StrategyTable] t
WHERE ParentCode = 'TOP')
ORDER BY t.stKey DESC;
I keep getting an error saying
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'ORDER'.
At the same time, it works for something WITHOUT a where clause; like
DECLARE #parent HierarchyId = (SELECT
[stPath] AS tmpPath
FROM [DEV].[tmp].[StrategyTable] t WHERE [ParentCode] = 'TOP')
WTF.......
DECLARE #neighbour HierarchyId = (SELECT TOP 1 [stPath] as tmpPath
FROM [DEV].[tmp].[StrategyTable] t
WHERE ParentCode = 'TOP'
ORDER BY t.stKey DESC);
This should accomplish what you want.

I need to remove the first three characters of every field in an SQL column [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table called "users" that has a column called "username." Recently, I added the prefix "El_" to every username in the database. Now I wish to delete these first three letters. How can I do that?
assuming MySql you can do something like this.
update users set username=substring(username,4);
which will update every row to not include el_, but this assumes that every row starts with the El_.
sqlfiddle - http://sqlfiddle.com/#!2/3bcf6/1/0
SELECT RIGHT(MyColumn, LEN(MyColumn) - 3) AS MyTrimmedColumn
This removes the first three characters from your result. Using RIGHT needs two arguments: the first one is the column you'd wish to display, the second one is the number of characters counting from the right of your result.
This should do!
EDIT: if you really like to remove this prefix from every username for good use an UPDATE statement as follows:
UPDATE MyTable
SET MyColumn = RIGHT(MyColumn, LEN(MyColumn) - 3)
This should work
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die(mysql_error());
$query = "SELECT username, id FROM users";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_numrows($result);
$i = 0;
while($i < $count){
$username = (mysql_result($result, $i, "username"));
$id = (mysql_result($result, $i, "id"));
$username = substr($username, 3);
$con=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
mysqli_query($con,"UPDATE users SET username = $username WHERE id = $id);
mysqli_close($con);
i++;
}

What's wrong with this SQL code syntax? [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 8 years ago.
Improve this question
I'm trying to implement this code into my script but I get a syntax error
INSERT INTO prospectstbl ( 'customerNumber', 'namePerson1', 'LnamePerson1', 'street', 'city', 'state', 'zip', 'homePhone', 'cellPhone', 'clientSince', 'clientLevel', 'closingDate', 'lastPaymentDate', 'currentBalance', 'repurchaseDate', 'repurchaseAmount', 'delinquentBalance', ) VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
and the error I get:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''customerNumber', 'namePerson1', 'LnamePerson1', 'street', ' at line 2
Any help would be greatly appreciated.
remove the '' at the column names and the , at the last column:
INSERT INTO prospectstbl ( customerNumber, namePerson1, LnamePerson1, street, city,
state, zip, homePhone, cellPhone, clientSince, clientLevel, closingDate,
lastPaymentDate, currentBalance, repurchaseDate, repurchaseAmount, delinquentBalance )
VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
There is a comma , after 'delinquentBalance'
use
`
instead of
'
And remove , after , delinquentBalance
or you can remove list of your columns
INSERT INTO prospectstbl VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
IIRC, single quotes (') are generally used for quoting literal values (strings and such) and indicating that certain tokens are NOT fieldnames. Graves (`) are used to indicate fields.
Try quoting your column names with graves (`) instead.
Also, as others have said, you have an extra comma at the end of your column name list. Remove this as well.