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 2 years ago.
Improve this question
SQL Server creating table error.
How to give system date, system date + 2 days while creating a table?
Is the system date the same as the current date?
You can try the SQL DEFAULT Constraint as shown below if I understood your question properly:
Create table Test(id int
, name varchar(20)
, dtDate datetime default DateAdd(dd, 2, getdate()))
insert into Test (id, name) values
(1, 'A')
select * from Test
Live db<>fiddle demo.
Related
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 21 hours ago.
This post was edited and submitted for review 10 hours ago.
Improve this question
dear gurus, SQL.
Please advise how to do the following:
You need to take a date from one column and join it with the time of another column,
and then add one day to the received date.
I wrote such a query, but on some data it gives a conversion error.
Please tell me a more optimal query so that it always works when combining the date and time format into datetime.
Thank you.
create table dt (date1 datetime, date2 datetime)
insert into dt values('19000101 17:17:00.000','19070101 17:51:00.000')
insert into dt values('19000101 18:20:00.000','19080101 18:21:00.000')
insert into dt values('20000101 06:00:00.000','20100101 06:40:00.000')
select
dateadd(dd,1,convert(datetime,convert(date,date1))+ convert(datetime,convert(time, date2)))
from dt
Here is an example where such an error could occur:
CREATE TABLE Example (
Duration TIME,
AdditionalDelay SMALLINT
)
INSERT INTO dbo.Example (Duration, AdditionalDelay)
VALUES ('00:01:02',3)
SELECT Duration+AdditionalDelay FROM dbo.Example
To fix this, you need to identify the proper unit of measure for AdditionalDelay and use DATEADD instead of +. For example:
SELECT DATEADD(MINUTE,AdditionalDelay,Duration) FROM dbo.Example
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 12 months ago.
Improve this question
I have a table whose Date column needs pushing ahead by 1 day.
My update query is:
UPDATE TABLENAME
SET DATECOL=DATECOL+1
Is this correct approach? Or do I need to use CTE, for example:
;WITH CTE AS (
SELECT ID, DATECOL
FROM TABLENAME)
UPDATE T
SET T.DATECOL=CTE.DATECOL+1
FROM TABLENAME T
JOIN CTE ON T.ID=CTE.ID
To add a value to any part of date you can use DATEADD function. In your case the part time is DAY.
UPDATE TABLENAME
SET DATECOL=DATEADD(DAY, 1, DATECOL)
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 years ago.
Improve this question
I want to Substring the string which is delimited
ABC/123/DEF
I want in
ABC in 1st column
123 in 2nd Column
DEF in 3rd Column
If your database in sql server you can try this:
declare #t table (name varchar(50))
insert into #t values ('ABC/123/DEF')
select PARSENAME(replace(name,'/','.'),3),PARSENAME(replace(name,'/','.'),2) , PARSENAME(replace(name,'/','.'),1) from #t
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 6 years ago.
Improve this question
Im using Microsoft SQL Server 2008 and i wanted to dump something from the database.
Its holding over 585k users.
I wanted to ask how i can select a specific row in a column
Like the column is named "User_ResetKey" in the database US_HBS_MEMBERS the table would be US_UserInfo, im really a noob in that maybe someone can help me the row number would be 123921
I mean how i can fetch data what is in the row number 123921?
regards,
jamsb
via using
Row_number()
here you are ,
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY [User_ResetKey] ) AS rownumber,
*
FROM [US_HBS_MEMBERS].[dbo].[US_UserInfo]
) AS myTable
WHERE rownumber = 123921
supposed your schema is 'dbo'.
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 6 years ago.
Improve this question
I have a EmailID_tbl that has email address of the users I have got request to "remove emails from EmailID_tbl if last login date for user is within the past 4 months."
Assuming that these are in the same table, you could just use a WHERE clause to determine what needs to be deleted via the DATEADD() function to subtract the appropriate number of months from GETDATE(), which would yield the current date :
-- This would delete every record in your table with LastLoginDates
DELETE
FROM EmailID_tbl
WHERE LastLoginDate < DATEADD(month,-4,GETDATE())
Here's a query that will do it:
DELETE
FROM EmailID_tbl
WHERE LastLoginDate <= DATEADD(mm, -4, GETDATE())
Change LastLoginDate to the actual name within your table which indicates the last login date, and change <= to >= if you actually mean to delete more active users instead of more inactive users.