SQL query alignment change when Arabic characters are inserted - sql

I have a query like this
SET QUOTED_IDENTIFIER OFF
SET DATEFORMAT 'mdy'
INSERT INTO TABLE1
(AccountID, TimeStamp, UserID, NodeID, Deleted, UserPriority, ParentRecordID, NodeLevel, Name, NodeClass, DeviceID, DeviceType, SubTypeLevel)
VALUES
(0, "10/03/2002 02:33:39", 0, 0, 0, 0, 0, 0,"XXXXXX",7000, 0, 0, 0`)
When I replace XXXXXX with منطقة تحكم بالبداية السريعة, the query after the string turns right to left like this
SET QUOTED_IDENTIFIER OFF
SET DATEFORMAT 'mdy'
INSERT INTO TABLE1
(AccountID, TimeStamp, UserID, NodeID, Deleted, UserPriority, ParentRecordID, NodeLevel, Name, NodeClass, DeviceID, DeviceType, SubTypeLevel)
VALUES
(0, "10/03/2002 02:33:39", 0, 0, 0, 0, 0, 0, "منطقة تحكم بالبداية السريعة", 7000, 0, 0, 0)
Please tell me how to overcome this.
I am using SQL server 2000 MSDE.

You can resolve this case by adding the letter N before each values entered (that need conversion)
For example:
INSERT INTO TABLE1(AccountID, TimeStamp, UserID, NodeID, Deleted, UserPriority,
ParentRecordID, NodeLevel, Name, NodeClass, DeviceID, DeviceType, SubTypeLevel)
VALUES
(0, "10/03/2002 02:33:39", 0, 0, 0, 0, 0, 0, "منطقة تحكم بالبداية السريعة"N, 7000, 0, 0, 0)
=>
Insert ... Into ... Values (id1,id2,..., N'Arabic word',N'Hebrew word',N'Chinese word');

This issue is solved when we add N before the nvarchar value.
SET QUOTED_IDENTIFIER OFF SET DATEFORMAT 'mdy' INSERT INTO ControlTreeEx (AccountID, TimeStamp, UserID, NodeID, Deleted, UserPriority, ParentRecordID, NodeLevel, Name, NodeClass, DeviceID, DeviceType, SubTypeLevel) VALUES (0, "10/03/2002 02:33:39", 0, 0, 0, 0, 0, 0, N'منطقة تحكم بالبداية', 7000, 0, 0, 0)

Related

Use same value in Insert (SQL)

I write a script to populate the database with values
Here is script row
INSERT INTO AbpUsers(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name, NormalizedEmailAddress, NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)
VALUES
('faithsdispatching#yahoo.com', 1, 0, 1, '', UPPER (EmailAddress), '', '', '', 0, GETDATE(), 1, 1, 0, 'AQAAAAEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD1Q==', 0)
For NormalizedEmailAddress field I need to use EmailAddress to Upper
I try to use this UPPER (EmailAddress) but get this error
Line 1: Invalid column name 'EmailAddress'.
Any ideas on how I can use EmailAddress column?
I don't think what you're asking is possible at the moment.
As a quick workaround, you can insert your data into a temporary table, run the UPPER() command on the column to hit them all at once, and then SELECT INTO your desired table from your temporary table.
CREATE TABLE #TemporaryAbpUsers
(
EmailAddress...,
IsActive...
);
INSERT INTO #AbpUsers(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name, NormalizedEmailAddress, NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)
VALUES
('faithsdispatching#yahoo.com', 1, 0, 1, '', 'faithsdispatching#yahoo.com', '', '', '', 0, GETDATE(), 1, 1, 0, 'AQAAAAEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD1Q==', 0);
UPDATE #TemporaryAbpUsers
SET NormalizedEmailAddress = UPPER(NormalizedEmailAddress);
SELECT * INTO AbpUsers
FROM #TemporaryAbpUsers;
Just change UPPER(EmailAddress) to UPPER ('faithsdispatching#yahoo.com')
INSERT INTO AbpUsers(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name, NormalizedEmailAddress, NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)
VALUES
('faithsdispatching#yahoo.com', 1, 0, 1, '', UPPER ('faithsdispatching#yahoo.com'), '', '', '', 0, GETDATE(), 1, 1, 0, 'AQAAAAEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD1Q==', 0)
Use a variable for EmailAddress
DECLARE #EmailAddress NVARCHAR(100);
SET #EmailAddress = N'faithsdispatching#yahoo.com';
INSERT INTO AbpUsers(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name, NormalizedEmailAddress, NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)
VALUES
(#EmailAddress, 1, 0, 1, '', UPPER(#EmailAddress), '', '', '', 0, GETDATE(), 1, 1, 0, 'AQAAAAEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD1Q==', 0);
For multiple inserts, then you could try an Insert-From-Select-From-Values.
INSERT INTO AbpUsers(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name, NormalizedEmailAddress, NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)
SELECT EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name,
UPPER(EmailAddress) AS NormalizedEmailAddress,
NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin
FROM (VALUES
('faithsdispatching#yahoo.com', 1, 0, 1, '', '', '', '', 0, GETDATE(), 1, 1, 0, 'AQAAAAEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD1Q==', 0)
, ('hellbendingsextra#funky.net', 1, 0, 1, '', '', '', '', 0, GETDATE(), 1, 1, 0, 'AQBBBBEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD2Q==', 0)
, ('yellowriverfishing#asia.org', 1, 0, 1, '', '', '', '', 0, GETDATE(), 1, 1, 0, 'AQCCCCEAACcQAAAAEHriGqDq6AuQs33CBdyNdwuiZboPua2e6aXn9MjB/qzo44kbXAAsIY77BIfzKLJD3Q==', 0)
) q(EmailAddress, IsActive, IsDeleted, IsEmailConfirmed, Name,
NormalizedUserName, Surname, UserName, AccessFailedCount, CreationTime, IsLockoutEnabled, IsPhoneNumberConfirmed, IsTwoFactorEnabled, Password, ShouldChangePasswordOnNextLogin)

prestashop - Can't load Order status at line 242 in file classes/PaymentModule.php

when I order with an obligation to pay
[PrestaShopException]
Can't load Order status
at line 242 in file classes/PaymentModule.php
237. }
238.
239. $order_status = new OrderState((int) $id_order_state, (int) $this->context->language->id);
240. if (!Validate::isLoadedObject($order_status)) {
241. PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $id_cart, true);
242. throw new PrestaShopException('Can\'t load Order status');
243. }
244.
245. if (!$this->active) {
246. PrestaShopLogger::addLog('PaymentModule::validateOrder - Module is not active', 3, null, 'Cart', (int) $id_cart, true);
247. die(Tools::displayError());
PaymentModuleCore->validateOrder - [line 58 - modules/ps_wirepayment/controllers/front/validation.php] - [9 Arguments]
Ps_WirepaymentValidationModuleFrontController->postProcess - [line 270 - classes/controller/Controller.php]
ControllerCore->run - [line 509 - classes/Dispatcher.php]
DispatcherCore->dispatch - [line 24 - override/classes/Dispatcher.php]
Dispatcher->dispatch - [line 28 - index.php]
insert with phpmyadmin the table
ps_order_state:
INSERT INTO `ps_order_state` (`id_order_state`, `invoice`, `send_email`, `module_name`, `color`, `unremovable`, `hidden`, `logable`, `delivery`, `shipped`, `paid`, `deleted`) VALUES
(1, 0, 1, 'cheque', 'RoyalBlue', 1, 0, 0, 0, 0, 0, 0),
(2, 1, 1, '', 'LimeGreen', 1, 0, 1, 0, 0, 1, 0),
(3, 1, 1, '', 'DarkOrange', 1, 0, 1, 0, 0, 1, 0),
(4, 1, 1, '', 'BlueViolet', 1, 0, 1, 1, 1, 1, 0),
(5, 1, 0, '', '#108510', 1, 0, 1, 1, 1, 1, 0),
(6, 0, 1, '', 'Crimson', 1, 0, 0, 0, 0, 0, 0),
(7, 1, 1, '', '#ec2e15', 1, 0, 0, 0, 0, 0, 0),
(8, 0, 1, '', '#8f0621', 1, 0, 0, 0, 0, 0, 0),
(9, 1, 1, '', 'HotPink', 1, 0, 0, 0, 0, 1, 0),
(10, 0, 1, 'bankwire', 'RoyalBlue', 1, 0, 0, 0, 0, 0, 0),
(11, 0, 0, '', 'RoyalBlue', 1, 0, 0, 0, 0, 0, 0),
(12, 1, 1, '', 'LimeGreen', 1, 0, 1, 0, 0, 1, 0),
(13, 1, 0, '', '#DDEEFF', 0, 0, 1, 0, 0, 0, 0);
Your ps_wirepayment module is trying to set an order status to an invalid / deleted id_order_state.
If you haven't modified it , bankwire modulee relies on ps_configuration "PS_OS_BANKWIRE" status value,
so make sure the ID value is valid and links to a valid order state in your database.

Insert after TRUE in condition in PostgreSQL

I need to insert my values if only they are not presented in my table.
I wrote the function:
do
$$
declare
v_video_config_bundle_id bigint;
v_are_records_exist boolean;
begin
select id from config_bundle into v_video_config_bundle_id where code = 'video';
select count(id) > 0 from config_bundle into v_are_records_exist
where config_bundle_id = v_video_config_bundle_id
and preference = 'true' and amount = 0 and repeatability in (1,7,14,21,30,45) and format='day';
case
when (v_are_records_exist = false) then
insert into config_plan(config_bundle_id, amount, repeatability, format, payment_amount, preference_type, preference, trial, weight, status, is_default)
values (v_video_config_bundle_id, 0, 7, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false),
(v_video_config_bundle_id, 0, 14, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false),
(v_video_config_bundle_id, 0, 21, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false);
end;
end;
$$
But I still get an exception ERROR:
syntax error at or near ";"
Position: 1420
How to fix it?
Let SQL make all decisions; put all the determination logic into a single SQL statement. You can do this by converting the filtering logic into NOT EXISTS (SELECT ... structure. So something like:
insert into config_plan(config_bundle_id, amount, repeatability, format, payment_amount, preference_type, preference, trial, weight, status, is_default)
with new_config ( amount, repeatability, format, payment_amount, preference_type, preference, trial, weight, status, is_default) as
( values ( 0, 7, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false),
( 0, 14, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false),
( 0, 21, 'day', 0, 'personal', true, false, 2, 'ACTIVE', false)
)
select amount, repeatability, format, payment_amount, preference_type, preference, trial, weight, status, is_default
from new_config nc
where not exists ( select null
from config_plan cp
where (cp.preference, cp.amount , cp.repeatability ,cp.format) =
(nc.preference, nc.amount , nc.repeatability ,nc.format)
) ;
The above is not tested as you did not supply table description and sample data. However, see here for an example of the technique.

How to replace text with a random number in SQL?

I have HeidiSQL and I have a 3MB query I need to run but I would like to replace certain text/values with a random number. How would I do that?
and I need to replace it, because there's a lot of rows.
INSERT INTO creature (`guid`, `id`, `map`, `zoneId`, `areaId`, `spawnMask`, `PhaseId`, `PhaseGroup`, `modelid`, `equipment_id`, `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `spawndist`, `currentwaypoint`, `curhealth`, `curmana`, `MovementType`, `npcflag`, `unit_flags`, `dynamicflags`, `VerifiedBuild`) VALUES
('#CGUID+0', 83855, 1116, 0, 0, 3, '0', 0, 0, 0, 1504.222, -2147.853, 90.73972, 0.6455684, 7200, 10, 0, 0, 0, 1, 0, 0, 0, 21463), -- 83855 (Area: 7120) (possible waypoints or random movement)
('#CGUID+1', 81244, 1116, 0, 0, 3, '0', 0, 0, 0, 1514.845, -2106.458, 92.60474, 2.908402, 7200, 0, 0, 0, 0, 0, 0, 0, 0, 21463), -- 81244 (Area: 7120) (Auras: 163908 - 163908)
('#CGUID+2', 81244, 1116, 0, 0, 3, '0', 0, 0, 0, 1484.29, -2122.714, 92.58028, 1.293478, 7200, 0, 0, 0, 0, 0, 0, 0, 0, 21463), -- 81244 (Area: 7120) (Auras: 163908 - 163908)
So basically I want to replace just where #CGUID+ is and just add a random number (preferabbly between 1-999999). Therefore it would add onto the current number to be like:
'4820940'
'2850331'
'2854962'
Note every last digit isn't changing, it's just the first text that's being replaced. But I need it to be random.
If you are using MySQL or SQLServer, a way to do that would be like this:
SELECT Replace(real_field1,'value to be replaced','new value') as scrambled_field1
FROM <any table>
WHERE <filter>
If you show your query, I could help you out.
Based on your SQL command, you could try something like this. I'm simplifying your query just to show syntax:
insert into table(column1) values (REPLACE('#CGUID+1','#CGUID',FLOOR(RAND()*(99999-1)+1))
Run the INSERT INTO statement as you have shown in your question.
Afterwards you run the following query:
UPDATE creature
SET guid = REPLACE(guid, '#CGUID+', ROUND((RAND() * (999999-1))+1))
WHERE guid LIKE '#CGUID+%'

INSERT with INNER JOIN and Predetermined Values

I'm trying to add 9500 or so records to a table from a different table, the problem is that the table I'm adding them to has an egregious amount of colums while the table I'm pulling from is pretty normalized so I'm not quite sure how to do the inner join on it, this is what I have so far:
INSERT INTO Products (Code, ManufacturerId, VendorId, IsActive, Name, NamePlural, ShortDescription, Description, UpSellMessage, Cost, Price, IsOnSale, SalePrice, IsShipable, ShipPrice, Weight, Length, Width, Height, HasCountryTax, HasStateTax, HasLocalTax, DateAdded, Keywords, Inventory_Tracked, DropShip, DownloadOneTime, DealTimeIsActive, MMIsActive, ProductType, RecurringSubscriptionPrice, PaymentPeriod, Term, BillingDelay, SaleType, BundleGroupID, ComputePrice, PriceUp, PriceChangedAmount, PriceChangedType, SwatchesPerRow, ChangeOnClick, ChangeOnMouseover, ShowCloseUpLink, LinkBigImage, SwatchAllignment, DescriptionAllignment, DetailLink)
FROM otherProducts table2
INNER JOIN table2
VALUES (table2.col1, 1, 1, 0, table2.col1, table2.col1, table2.col4, table2.col4, 'some message that does not matter', table2.col3, table2.col2, 0, '0', 1, '8', '3', '8', '8', '8', 1, 1, 1, '12/27/2013', ' ', 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 1, '0', 0, 0, 0, 0, 0, 0, 0, 0, table2.col1+'.aspx');
I can see this is a giant mess, and it just gives me errors, can anyone help me with this?
You want the insert . . . select syntax:
INSERT INTO Products (Code, ManufacturerId, VendorId, IsActive, Name, NamePlural, ShortDescription, Description, UpSellMessage, Cost, Price, IsOnSale, SalePrice, IsShipable, ShipPrice, Weight, Length, Width, Height, HasCountryTax, HasStateTax, HasLocalTax, DateAdded, Keywords, Inventory_Tracked, DropShip, DownloadOneTime, DealTimeIsActive, MMIsActive, ProductType, RecurringSubscriptionPrice, PaymentPeriod, Term, BillingDelay, SaleType, BundleGroupID, ComputePrice, PriceUp, PriceChangedAmount, PriceChangedType, SwatchesPerRow, ChangeOnClick, ChangeOnMouseover, ShowCloseUpLink, LinkBigImage, SwatchAllignment, DescriptionAllignment, DetailLink)
select table2.col1, 1, 1, 0, table2.col1, table2.col1, table2.col4, table2.col4, 'some message that does not matter', table2.col3, table2.col2, 0, '0', 1, '8', '3', '8', '8', '8', 1, 1, 1, '12/27/2013', ' ', 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 1, '0', 0, 0, 0, 0, 0, 0, 0, 0, table2.col1+'.aspx'
FROM otherProducts table2;
I don't think you need to do a join at all.