I'm trying to get my database within my application to search by phone numbers. I've got to the "Search Criteria Builder" screen, but I can't seem to get my query right.
This is the query I've tried and that is when I get the "converting from nvarchar to numeric" error:
SELECT phoneNumber, serviceDate, firstName, lastName, billingAddress, emailAddress, vehicleMake, vehicleModel, vehicleYear, vehicleColor, vehicleMileage
FROM [Table]
WHERE (phoneNumber LIKE #phoneNumber + N'%')
Here is the table created:
CREATE TABLE [dbo].[Table] (
[phoneNumber] NUMERIC (18) NOT NULL,
[serviceDate] DATE NULL,
[firstName] NCHAR (10) NULL,
[lastName] NCHAR (10) NULL,
[billingAddress] NVARCHAR (50) NULL,
[emailAddress] NVARCHAR (50) NULL,
[vehicleMake] NCHAR (10) NULL,
[vehicleModel] NCHAR (10) NULL,
[vehicleYear] INT NULL,
[vehicleColor] NCHAR (10) NULL,
[vehicleMileage] INT NULL,
CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED ([phoneNumber] ASC)
);
If the VB code is needed, I will provide it as well.
If you're going to treat phone "numbers" like strings, why are you storing them as numeric? You can do this:
WHERE CONVERT(VARCHAR(32), phoneNumber) LIKE #phonenumber + '%';
(Also note that you don't need Unicode here - there is no number with umlauts.)
But better to change the data type of the column IMHO.
Related
SQL
replace into articles(id,grade,no,title,content,newchars,update_time)
values(1394823098212,'1','8','title','**LongUtf8String**',1614001996557)
If the length of LongUtf8String exceeds 2689 bytes, the operation will fail, without any exception.
In sqlite command line and navicat, it can work.
Table definition:
create table if not exists articles (
id long not null primary key,
grade tinyint not null,
no smallint not null,
title varchar(255) not null,
content text not null,
newchars text not null
);
I can't find any configuration items in SQLiteConfig.
Are there any ways to overcome the limit?
Thanks!!!
It is my fault:(((
I limited the length when check parameters, and discard it without prompt.
I'm trying to use node-pg-migrate to handle migrations for an ExpressJS app. I can translate most of the SQL dump into pgm.func() type calls, but I can't see any method for handling actual INSERT statements for initial data in my solution's lookup tables.
It is possible using the pgm.sql catch all:
pgm.sql(`INSERT INTO users (username, password, created, forname, surname, department, reviewer, approver, active) VALUES
('rd#example.com', 'salty', '2019-12-31 11:00:00', 'Richard', 'Dyce', 'MDM', 'No', 'No', 'Yes');`)
Note the use of backtick (`) to allow breaking the SQL statement across multiple lines.
You can use raw sql if you needed.
Create a migration file with the extension .sql and write usual requests.
This article has a great example.
My example:
-- Up Migration
CREATE TABLE users
(
id BIGSERIAL NOT NULL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
class_id INTEGER NOT NULL,
created_at DATE NOT NULL,
updated_at DATE NOT NULL
);
CREATE TABLE classes
(
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
health INTEGER NOT NULL,
damage INTEGER NOT NULL,
attack_type VARCHAR(50) NOT NULL,
ability VARCHAR(50) NOT NULL,
created_at DATE NOT NULL,
updated_at DATE NOT NULL
);
INSERT INTO classes (id,
name,
health,
damage,
attack_type,
ability,
created_at,
updated_at)
VALUES (0,
'Thief',
100,
25,
'Archery Shot',
'Run Away',
NOW(),
NOW());
-- Down Migration
DROP TABLE users;
DROP TABLE classes;
I have one Azure SQL server where I have several databases. I need to be able to query across these databases, and have at the moment solves this through external tables. A challange with this solution is that external tables does not support all the same data types as ordinary tables.
According to the following article the solution to incompatible data types are to use other similiar ones in the external table.
https://learn.microsoft.com/en-us/azure/sql-data-warehouse/sql-data-warehouse-tables-data-types#unsupported-data-types.
DDL for table in DB1
CREATE TABLE [dbo].[ActivityList](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Registered] [datetime] NULL,
[RegisteredBy] [varchar](50) NULL,
[Name] [varchar](100) NULL,
[ak_beskrivelse] [ntext] NULL,
[ak_aktiv] [bit] NULL,
[ak_epost] [bit] NULL,
[Template] [text] NULL
CONSTRAINT [PK_ActivityList] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
DDL for external table in DB2
CREATE EXTERNAL TABLE [dbo].[NEMDBreplicaActivityList]
(
[ID] [int] NOT NULL,
[Registered] [datetime] NULL,
[RegisteredBy] [varchar](50) NULL,
[Name] [varchar](100) NULL,
[ak_beskrivelse] [nvarchar](4000) NULL,
[ak_aktiv] [bit] NULL,
[ak_epost] [bit] NULL,
[Template] [varchar](900) NULL
)
WITH (DATA_SOURCE = [DS],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'ActivityList')
Querying the external table NEMDBreplicaActivityList produces the following error
Error retrieving data from
server.database.windows.net.db1. The
underlying error message received was:
'PdwManagedToNativeInteropException ErrorNumber: 46723, MajorCode:
467, MinorCode: 23, Severity: 16, State: 1, ErrorInfo: ak_beskrivelse,
Exception of type
'Microsoft.SqlServer.DataWarehouse.Tds.PdwManagedToNativeInteropException'
was thrown.'.
I have tried defining the ak_beskrivelse column as other external table legal datatypes, such as varchar, with the same result.
Sadly I'm not allowed to edit the data type of columns in the db1 table.
I assume that the error is related to the data type. Any ideas how to fix it?
I solved a similar problem to this by creating a view over the source table which cast the text value as varchar(max), then pointed the external table to the view.
So:
CREATE VIEW tmpView
AS
SELECT CAST([Value] AS VARCHAR(MAX))
FROM [Sourcetable].
Then:
CREATE EXTERNAL TABLE [dbo].[tmpView]
(
[Value] VARCHAR(MAX) NULL
)
WITH (DATA_SOURCE = [myDS],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'tmpView')
Creating the view and casting the text value worked perfect for me 😊
Thank you!
Created view vw_TestReport:
SELECT CAST([Report Date] AS VARCHAR(MAX)) AS [Report Date]
FROM dbo.TestReport
And created external table from view:
CREATE EXTERNAL TABLE [dbo].[TestReport](
[Report Date] [varchar](max) NULL
)
WITH (DATA_SOURCE = [REFToDB],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'vw_TestReport')
We are very new to memsql/mysql and we are trying to play around with a memsql installation.
It is installed on a CentOS7 virtual machine and we are running version 5.1.0 of MemSQL.
We are receiving the error from one of the queries we are attempting:
ERROR 1889 (HY000): Bad distributed join plan: result table shard keys do not match. Please contact MemSQL support at support#memsql.com.
On one of our queries
We have two tables:
CREATE TABLE `MyObjects` (
`Id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(128) NOT NULL,
`Description` VARCHAR(256) NULL,
`Boolean` BIT NOT NULL,
`Int8` TINYINT NOT NULL,
`Int16` SMALLINT NOT NULL,
`Int32` MEDIUMINT NOT NULL,
`Int64` INT NOT NULL,
`Float` DOUBLE NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
SHARD KEY (`Id`),
PRIMARY KEY (`Id`)
);
CREATE TABLE `MyObjectDetails` (
`MyObjectId` INT,
`Int32` MEDIUMINT NOT NULL,
SHARD KEY (`MyObjectId`),
INDEX (`MyObjectId`)
);
And here is the SQL we are executing and getting the error.
memsql> SELECT mo.`Id`,mo.`Name`,mo.`Description`,mo.`Boolean`,mo.`Int8`,mo.`Int16`,
mo.`Int32`,mo.`Int64`,mo.`Float`,mo.`DateCreated`,mods.`MyObjectId`,
mods.`Int32` FROM
( SELECT
mo.`Id`,mo.`Name`,mo.`Description`,mo.`Boolean`,mo.`Int8`,
mo.`Int16`,mo.`Int32`,mo.`Int64`,mo.`Float`,mo.`DateCreated`
FROM `MyObjects` mo LIMIT 10 ) AS mo
LEFT JOIN `MyObjectDetails` mods ON mo.`Id` = mods.`MyObjectId` ORDER BY `Name` DESC;
ERROR 1889 (HY000): Bad distributed join plan: result table shard keys do not match. Please contact MemSQL support at support#memsql.com.
Does anyone know why we are receiving this error, and if there is a possible change we can make to help alleviate this issue?
The one thing we do know is it has something to do with the inner select as if I pull it out and do the join it works, however we only get 10 total rows from the join. What we are attempting is getting the top 10 from the main table and include all of the details from the right.
We also tried changing the MyObjectDetails table to have an empty SHARD KEY, but that resulted in the same error.
SHARD KEY()
We also added an auto-incrementing Id column to the details table and put the shard on that column, and yet still received the same error.
Thanks in advance for any help.
UPDATE:
I contacted MemSQL through email (huge props to their customer service by the way -- very fast response time, less than a couple hours)
But from what Mike stated I changed the table to be a REFERENCE table and removed the SHARD KEY part of the create table statement. Once I did this, I was able to run the queries. I am not 100% sure on what ramifications this will have but it fixed my issue at hand. Thanks
CREATE REFERENCE TABLE `MyObjects` (
`Id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(128) NOT NULL,
`Description` VARCHAR(256) NULL,
`Boolean` BIT NOT NULL,
`Int8` TINYINT NOT NULL,
`Int16` SMALLINT NOT NULL,
`Int32` MEDIUMINT NOT NULL,
`Int64` INT NOT NULL,
`Float` DOUBLE NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
PRIMARY KEY (`Id`)
);
Thanks to Mike Gallegos for looking into this, adding a summary of his answer here:
The error message here is bad, but the reason for the error is that MemSQL does not currently support a distributed left join where the left side (the Limit subquery in this case) has a LIMIT operator. If you cannot rewrite the query to do the limit after the join, then you could change the MyObjects table to a reference table to work around the issue.
I have a table like so..
CREATE TABLE [dbo].[Locations_Hours](
[LocationID] [int] NOT NULL,
[sun_open] [nvarchar](10) NULL,
[sun_close] [nvarchar](10) NULL,
[mon_open] [nvarchar](10) NULL,
[mon_close] [nvarchar](10) NULL,
[tue_open] [nvarchar](10) NULL,
[tue_close] [nvarchar](10) NULL,
[wed_open] [nvarchar](10) NULL,
[wed_close] [nvarchar](10) NULL,
[thu_open] [nvarchar](10) NULL,
[thu_close] [nvarchar](10) NULL,
[fri_open] [nvarchar](10) NULL,
[fri_close] [nvarchar](10) NULL,
[sat_open] [nvarchar](10) NULL,
[sat_close] [nvarchar](10) NULL,
[StoreNumber] [int] NULL,
[LocationHourID] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_Locations_Hours] PRIMARY KEY CLUSTERED
(
[LocationHourID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
And SubSonic 3 is generating a class with the following properties
int LocationID
string monopen
string monclose
string tueopen
string tueclose
string wedopen
string wedclose
string thuopen
string thuclose
string friopen
string friclose
string satopen
string satclose
string sunopen
string sunclose
int? StoreNumber
int LocationHourID
When I try to perform a query against this class like so..
var result = DB.LocationHours.Where(o => o.LocationID == _locationId);
This is the resulting SQL query that SubSonic generates.
SELECT [t0].[LocationHourID], [t0].[LocationID], [t0].[StoreNumber]
FROM [dbo].[Locations_Hours] AS t0
WHERE ([t0].[LocationID] = 4019)
I cannot figure out why SubSonic is omitting the nvarchar fields when it generates the SELECT statement. Anyone got any ideas?
I wasn't ever able to solve this problem. I ended up just executing a plain old DataReader and 'manually' populated my objects.
If anyone comes along later with an answer, I will change the accepted answer.