|
please tell me
query in sql server 2005 getting 14 days back date from today date.
thanks
You get the best out of others when you give the best of yourself.
|
|
|
|
|
Use DATEADD and supply a negative number.
|
|
|
|
|
I have tended to always do this the lazy way:
select getdate()-14
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Bloody hell I've been using TSQL for (way too many years) and never run across that one . Had to actually test it before I believed it worked . Thanks you. Have 5
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah - I just sit back with the beer and chips and let the computer do the work for me most of the time
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
I was searching for Set ParseOnly On support from a managed application. This directive prohibits being used from within a stored procedure.
At the same time, while searching somewhere I referenced about a SQL Parser assembly and a sample codesnippet like vbSQLParser .
I was searching through my system assemblies and also on the Internet but could not make out which assembly or component does this source from? Can someone throw some hint or if it is a download URL from Microsoft or elsewhere, a download URL would be appreciated.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Looks like I am getting it.
Microsoft.SqlServer.Common assembly seems to have a lot of utility towards this objective. Trying to research on it and harness its benefits.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
--> The datatype "Decimal(18,0)"...
--> What is the meaning of the values in the parenthesis..?
J A Nasir K
|
|
|
|
|
|
They got to learn somewhere - I would have thought it was taught at an earlier time than CP
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
decimal decimal(p,s) Where p is a precision value; s is a scale value.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
Dears,
I'm using MS SQL Server 2005 and i'm inserting a time value which is ArrivalTime in column and at the end of the trip i insert another time value in another column which is leavingTime
And I want to save the diffrence between the two times in another Column TripTime
so the value in TripTime should be LeavingTime - ArrivalTime
How can this be done.
Thanks
|
|
|
|
|
To get the difference between 2 dates use the DATEDIFF function.
But there's no need to store the TripTime since you've already stored Leaving and Arrival. If you store it you are going to risk the data getting out of sync if there are any changes. Instead, whenever you need to get the tip time, just make a call to DATEDIFF using leaving and arrival times.
|
|
|
|
|
Well, it depends. If you want to be able to search on the trip time - find all trips where the trip time was longer than/shorter than x amount, then you might want to build a computed column and index the table on that computed column, although indexes on computed columns have a set of prerequisite option values which IIRC aren't the defaults, so you have to be a bit careful about setting the options to ensure that the index gets used.
If you can't guarantee the options then perhaps a trigger to compute and store this value would be appropriate.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Delete can be rolled back but Truncate cannot be rolled back.
Begin Transaction
Delete Del_Details
Rollback
and i'm getting my deleted records
but still when i use ....
Begin Transaction
Truncate Table Del_Details
Rollback
This command is also giving me my deleted records..
So where is the difference between Delete and Truncate in respect of Rollback.......Plz explain
|
|
|
|
|
in Sql Server 2000 may be true for other DB's but i have not looked into it, the delete command cheks for data integrety(sp?) and actually removes each record from the tree if there are no FK problems. Truncate basically just moves the pointer from the bottom of the tree to the top and forgets that there was ever any data in there, essientially removes any reference to where that was in memory and starts over. Therefore Rollback cant work beacuse there is nothing to rollback, there is no longer any reference to whatever was in that table. I dont know for sure how they store the data, but using the analogy of a bTree helps when i explain it to people at work. hopefully i explained that right.
|
|
|
|
|
BOL: The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log.
If you are in a transaction, it probably does not reuse the pages until COMMIT. Also, truncate can not be run when foreign keys are present.
|
|
|
|
|
You are having trouble with this one aren't you, are you expecting a different response this week!
clickety[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When you asked this question before (^) several of us gave you the fullest explanation possible. If you don't believe us the try google or something, because no matter how many times you ask the real answer is going to be the same.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi all,
Am trying to upsize certain tables from MSAccess database to SQL database.I have a preexisting database with tables which are vacant in SQL.While i try to upsize the database tables from MSAccess 2003 to SQL server am getting an error.I tried to upsize three tables out of which one was upsized fine with all data imported with out errors(was not having foreign key relations).But the other two are shooting errors and not upsizing .
The error looks like "
"Server Error 3726:"Couldnot drop object 'tablname' because it is referenced by a Foreign key constraint."
I tried to remove all the foreign key connections in SQL tables and still getting the same error.
Since am doing this for the first time,am unsure what exactly is the way to go?
Any help will be welcome.
Many Thanks,
|
|
|
|
|
The following code is giving me the described error. I have included my debug trace also.
Apparently if the "LIKE" text is not found at all is causing this behavior.
How do I get around it?
Thanks for your help.
Vaclav
m_FDRecordset->Open(AFX_DB_USE_DEFAULT_TYPE,
"SELECT * FROM [Log] WHERE [Callsign] LIKE '" + text + "%'",
CRecordset::readOnly );
CString strSQL = m_FDRecordset->GetSQL( );
TRACE("\n SQL %s ",strSQL);
Debug trace
SQL SELECT * FROM `Log` WHERE `Callsign` LIKE 'AA1A%' Error: attempted to position cursor on empty recordset.
Attempt to scroll past end or before beginning of data.
First-chance exception in FD2008.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
ALWAYS CHECK RETRUN FROM FUNCTION
if(!m_FDRecordset->Open(AFX_DB_USE_DEFAULT_TYPE,
"SELECT * FROM [Log] WHERE [Callsign] LIKE '%" + text + "%' ",
CRecordset::readOnly ))
{
// ... handle error here
};
ALWAYS CHECK FOR EOF
if(m_FDRecordset->IsEOF())
{
// NO DATA FOUND
};
<div class="ForumMod">modified on Wednesday, May 21, 2008 12:27 PM</div>
|
|
|
|
|
Since it's tracing the SQL I would assume it's the statement after the TRACE which is causing the exception. You probably need to check IsBOF and IsEOF to ensure that some rows were returned before trying to reference any fields.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Thanks - I guess I was "half a bubble off" looking at the wrong statement and assuming it was the Open recordset failing.
I guess I should have checked the return from Open!
Thanks again.
Vaclav
|
|
|
|
|
Find Top 5 Records without using the Top command..????
|
|
|
|
|
set rowcount 5
select xyz
from table
order by ....
Bob
Ashfield Consultants Ltd
|
|
|
|