ServiceStack.OrmLite: How to Insert SYSDATE - oracle11g

I am using OrmLite Oracle in C#. I want to insert current sysdate instead of DateTime.Now in column having date data type, i.e. taking the date at the database end and not the calling code. How can I do this?

Related

How should I format my string to pass it to my database via TIBCO BW6?

I'm new to TIBCO BW6. This is my scenario. I have a .csv file, and one of my columns is a string in this format: '31/08/2021 15:18:00'
I created a process that reads my file and inserts a new row into my database. I have a problem with the date.
In my palette JDBC Update, the date is a timestamp. When I match the input, the right pattern for matching my string in datetime is pattern yyyy-mm-dd hh:mm:ss.
To do this kind of thing the best solution is generally to use the SQL database formatting functions in your SQL query.
Something like this (for ORACLE) :
insert into table_name
(my_date_field)
values (TO_DATE('2022/01/23 11:25:44', 'yyyy-mm-dd hh24:mi:ss'));
In BusinessWorks the query would look like this and you would have to map the value of the field corresponding to the '?' with your actual timestamp :
insert into table_name
(my_date_field)
values (TO_DATE(?, 'yyyy/mm/dd hh24:mi:ss'));

Outputting datetime date to dropdown list from SQL Server database

I have a webpage that populates a dropdown control using SqlDataSource.
I want to return date values from a table and output them into the dropdownbox,
The code I have to do this, which works in the query builder is as follows:
SELECT DISTINCT CONVERT (varchar(10), Appointmentdatetime, 103)
FROM Visit AS date
However when I run this, the following error occurs
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
When I modify the query to
SELECT DISTINCT
CONVERT(VARCHAR(10), Appointmentdatetime, 126)
FROM Visit AS date
it behaves correctly.
I need the date to output to dd/MM/yyyy. Can anyone offer any help on the problem?
Thanks
You could also try this
SELECT convert(varchar, cast(Appointmentdatetime as date), 103) FROM Visit as date
try this one
SELECT DISTINCT CONVERT (Date, Appointmentdatetime, 103) as dates FROM Visit

sqlite compound where datetime queries

I have a 'presure' table in an sqlite3 database with a 'timestamp' column filled by datetime('now') by a python program which runs periodically adding line at a time to my table.
I'd like to query the database so as to return all the values just from today.
Easy enough:
select * from presure where timestamp like "2014-07-10 %";
BUT, I don't want to have to modify the query each time I run it, today ,tomorrow or any other day. So what I want is someway to replace the date string and wild card with a sub query that generates todays date like:
select date('now');
but I have been unsuccessful compounding the two queries. What am I missing?
In SQL, strings are concatenated with ||:
SELECT * FROM presure WHERE timestamp LIKE date('now') || '%'

Insert multiple rows into SQL Server based on start and end dates

I need to insert several rows into a SQL Server database based on Start Date and End Date textboxes.
E.G. tbStartDate.Text = "25/12/2012" and tbEndDate.Text = "29/12/2012" therefore I need to insert individual rows for the following dates:
25/12/2012
26/12/2012
27/12/2012
28/12/2012
29/12/2012
Please can you help me with the necessary T-SQL to achieve this?
As always there are a few ways. Here are some of them:
You can write code in your app that loops through the days and inserts a single record per day. (generally the worst design)
You can call some SQL script to do it all in the database.
You can wrap up your SQL script in a stored procedure and pass in the start and end date and get the stored procedure to do it for you.
You can cross join to a pre existing tally table and use it to generate your records.
If you can provide
-the version of SQL Server that you're using
-what the table looks like
-whether you're using C# or VB
then we can help further as it can be difficult to pass dates into databases. It can be particularly difficult if you do not validate them.
Anyway here is option 3 for you.
CREATE PROC dbo.t_test
#StartDate DATETIME,
#EndDate DATETIME
AS
WHILE #StartDate <= #EndDate
BEGIN
INSERT INTO YourTable(YourDateField) VALUES (#StartDate)
SET #StartDate = DATEADD(d,1,#StartDate)
END
Then you need to call this stored procedure (called dbo.t_test) from ASP.Net and pass in your two date parametes as dates.
Declare #Startdate datetime
Select #Startdate='20121025'
While #Startdate<='20121029'
begin
if not exists(select * from dummy where DATE=#Startdate)
insert into dummy (date) values (#Startdate)
set #Startdate=#Startdate + 1
end;

Insert current date into ASP SQL

have a table with a transaction date in it. It is set as a timestamp and basically I want on creation of a new record that field automatically inserts the current date. I am using visual studio 2010 and ASP.net SQL not sure how to go about it. Dont need SQL injection protection for this just a simple way of doing it. Any ideas?
Mark
Oracle has a SYSDATE() function,
SqlServer has GETDATE()
MySQL has NOW()
Use it in your DML (SELECT, INSERT) statements
INSERT INTO [AdventureWorks].[dbo].[ErrorLog]
([ErrorTime]
,[UserName]
,[ErrorNumber]
,[ErrorMessage]
)
VALUES
(GetDate() --This will work for MSSQL
,'userName'
,7551
,'I inserted the current date/Time'
)
or (again for SQL server)
ALTER TABLE dbo.ErrorLog ADD CONSTRAINT
DF_ErrorLog_ErrorTime_current_DateTime DEFAULT (getdate()) FOR ErrorTime)
If the above code is in a stored procedure, then getDate() should work. If it is a sql command string that you are sending via ado.net, then you need to do this (example in VB):
sqlString="Insert into myTable (myDateTimeColumn) Values ('" & now() & "')"
myCommand.Execute(sqlString) ... etc.

Resources