In my database, i have table :
ID int
UserName nvarchar(50)
NoiDung ntext
Trangthai nvarchar(50)
GhiChu ntext
NgayThucHien datetime
ThoiHan datetime
And SQL procedure to Insert:
GO
ALTER PROCEDURE [dbo].[Insert_DBangKe]
#UserName nvarchar(50),
#NoiDung ntext,
#TrangThai nvarchar(50),
#GhiChu ntext,
#Ngay datetime,
#Han datetime
AS
INSERT INTO DBangKe
(
UserName,
NoiDung,
TrangThai,
GhiChu,
NgayThucHien,
ThoiHan
)VALUES
(
#UserName,
#NoiDung,
#TrangThai,
#GhiChu,
#Ngay,
#Han
)
In my Project Web, i have APSxGridView to show and allow insert, delete, edit.
APSxGridView load with no rows
When i Click Insert, and type value, then select date from AspxDateedit. Click Update, its show error:
Invalid cast from 'Int32' to 'DateTime'.
How i can repair this?
Related
I am trying to use Athena to query some data I have stored in an s3 bucket in parquet format. I have field called datetime which is defined as a date data type in my AWS Glue Data Catalog.
When I try running the following query in Athena, I get the error below:
SELECT DISTINCT datetime
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > '2018-09-14'
ORDER BY datetime DESC;
And the error:
Your query has the following error(s):
SYNTAX_ERROR: line 3:16: '>' cannot be applied to date, varchar(10)
What am I doing wrong here? How can I properly filter this data by date?
the string literal that you provide has to be casted to a date, in order to compare to a date.
where datetime = date('2019-11-27')
its having issue with the string literal used for date filter. Use WHERE datetime > date '2018-09-14'
from_iso8601_date or date should work.
SELECT DISTINCT datetime
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > from_iso8601_date('2018-09-14')
ORDER BY datetime DESC;
both return a proper date object.
SELECT typeof(from_iso8601_date('2018-09-14'))
Bit late here, but I had the same issue and the only workaround I have found is:
WHERE datetime > (select date '2018-09-14')
I have an error with my trigger. it show
LINE/COL ERROR
-------- --------------------------------------------
2/2 PL/SQL: SQL Statement ignored
2/6 PL/SQL: ORA-00922: missing or invalid option
I want this trigger run if the customertype is member.
Here are my table
TABLE CUSTOMER
CREATE TABLE CUSTOMER
(CUSTOMERID VARCHAR2(100) primary key,
CUSTOMERNAME VARCHAR2(50),
CUSTOMERADDRESS VARCHAR2(100),
CUSTOMERPHONE VARCHAR2(15),
CUSTOMEREMAIL VARCHAR2(50),
CUSTOMERTYPE VARCHAR2(15)
)
TABLE MEMBER
CREATE TABLE MEMBER
(MEMBERID VARCHAR2(100),
USERNAME VARCHAR2(25),
PASSWORD VARCHAR2(10),
CUSTOMERID VARCHAR2(100),
CONSTRAINT FK_Member Foreign Key (CustomerId)
REFERENCES Customer(CustomerId)
);
This is my trigger
CREATE or replace TRIGGER insertMember
after insert ON CUSTOMER
for each row
BEGIN
SET NOCOUNT ON
If (select customertype from customer) = 'member'
begin
INSERT INTO MEMBER (customerid ) values
(:new.customerid);
END insertMember;
/
I have a table 'Person' with columns as 'Person_id as primary key','DOB' and 'place' as follows:
'Person'
Person_id |Name|DOB | place
Another table is "employee" where emp_id is primary key as follows:
'employee'
Person_id |emp_id|dateofjoin
And one more table "Details":
'Details'
emp_id|competency|rating
Now what i want is once i add the 'Person' table details the rest of the two tables as'employe' and 'Details' to get updated also with respect to the new Person added in the Person table. So, how can i have this using sql query? Also i want to clear that i am not very much familiar with database.
I think your after something like this ( for SQL Server ):
Create Procedure dbo.CreateMyEmployee ( #empName varchar(50),
#dob datetime,
#doj datetime,
#place as varchar(100),
#competency varchar(100),
#rating int)
As
Begin
Declare #empId int
Begin Transaction
Begin Try
Insert into Person (Name, DOB, Place)
Values ( #empName, #dob, #place)
Insert into employe (Name, dateofJoin) -- Assuming emp_id is identity columen
Values ( #empName, #doj)
Select #empId = SCOPE_IDENTITY()
Insert Into Details(emp_id, competency, rating)
Values (#empId, #competency, #rating)
Commit transaction
End Try
Begin Catch
Rollback Transaction
SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_MESSAGE() AS ErrorMessage
End Catch
End
I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9.
This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp on column brand but failed on column revision;
For example
SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$'
and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms)
However, if regexp is applied on different column, then I get the error
SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
and the error message is invalid operand: SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
Both brand and revision are of TEXT type. The table creation schema is as below:
CREATE TABLE `TDevice` (
`id` INTEGER NOT NULL,
`brand` varchar(128) NOT NULL,
`model` varchar(128) NOT NULL,
`revision` TEXT,
PRIMARY KEY(id)
);
Both brand and revision are of TEXT type. The table creation schema is as below:
No They are different see your table description correctly if you change the TEXT to varchar it will work fine.
Or I will check and inform you how to use regex or can we use regex with TEXT datatype.
or you can convert(CAST) your TEXT to varchar and can perform the match operations
See this post for how to CAST TEXT into varchar
Need to convert Text field to Varchar temporarily so that I can pass to a stored procedure
The difference between brand and revision is that brand cannot accept NULL text. After I fill the revision with empty string '':
UPDATE TDevice SET revision='' WHERE revision IS NULL
, this invalid operand error is resolved.
I have a game, and in the database I'm saving the user actions by date & time.
CREATE TABLE user_actions
(
aId BIGSERIAL PRIMARY KEY NOT NULL,
userId BIGINT NOT NULL REFERENCES users(uId) DEFERRABLE INITIALLY DEFERRED,
aDate TIMESTAMP without time zone DEFAULT now(),
aType INTEGER NOT NULL DEFAULT 0
);
My users are identified with email
CREATE TABLE users(
uId BIGSERIAL PRIMARY KEY NOT NULL,
uName VARCHAR (50) NOT NULL,
uEmail VARCHAR (75) UNIQUE NULL
);
and each day new prizes are added each day has a different number of prizes
CREATE TABLE prizes(
pId BIGSERIAL PRIMARY KEY NOT NULL,
pDate TIMESTAMP without time zone DEFAULT now(),
pType INTEGER NULL
pSize INTEGER NULL
);
This query list the userId and his last action date, per user
select distinct userId, max(aDate) from user_actions GROUP BY userId order by userId;
I want to create a query that will count the number of prizes added since each user last action.
I'm running:
OS: Debian
DB: Postgresql
code: Django
I think I will use CTE though It has not been tested
WITH last_actions AS (
SELECT DISTINCT userId, MAX(aDate) as last_logged
FROM user_actions
GROUP BY userId ORDER BY userId)
SELECT a.userId, COUNT(b.pDate)
FROM last_actions a, prizes b
WHERE b.pDate >= a.last_logged
GROUP BY a.userId;