How Does SQL Server Calculate GETDATE? (was Newbie Question)

Mar 8, 2006

My apologies if my question seems rather naive, but I'm looking for some info on how SQL Server (2K) calculates the GETDATE info. Is it from an internal algorithm of some type, or does it simply pull the info from the local server info?

Thanks to all.

View 3 Replies


ADVERTISEMENT

How To Calculate Difference Between Getdate And T1 How Many Days

Oct 10, 2013

i have a table

a1
-----
id t1

How can I calculate the difference between getdate() and t1 how many days.

View 3 Replies View Related

Getdate() >= Startdate And Getdate() <= Enddate

Oct 4, 2000

Please i need an exmple of ur solution, thanks :)

I'm using some files to show certain pages on certain date for an example

File name : aa.doc
start date: 10/02/00
end date : 10/03/00

But it expires on 10/02/00, here is the strored procedure:

Before the date comes, it expires the page
Here is my stored procedure:

"
SELECT startdate, enddate,archivedate
and (startdate is null or (getdate() >= startdate and getdate() <= enddate))
and (archivedate is null or (getdate() <= archivedate))
group by startdate, enddate order by startdate desc "

Thankx a lot

View 1 Replies View Related

SQL SERVER Invalid Use Of 'getdate' Within A Function.

Feb 5, 2004

alter function sp_insert_newCustomer
(
@CrmDbIDint,
@DealerIDint
)
returns int
--@AddressLastUpdatedatetime
as
begin

declare @date datetime
set @date = getdate()

insert into dbo.CRMDB values(
@DealerID,
@date --@CreatedDate,
)

return @@Identity
end
GO

View 3 Replies View Related

Sql Server 2005 GETDATE() Function

Apr 22, 2008

I have a small problem using the GETDATE() function from a JAVA program using the MS JDBC connector.

When I use the SQL Mangment Studio Express to execute this query:

SELECT GETDATE()
it returns 2008-04-22 16:25:03.690 which is OK !!

I want to get that same value using a Java program so I do that query but when I display it it shows as:

2008-04-22 and there is no time there !
I tried formatting the date to include time but it shows as: 04/22/2008 12:00:00 AM
So maybe the time isnīt there ?

This is the code i am using:

Statement st = con.createStatement();
String sql = "SELECT GETDATE()";
ResultSet result1 = st.executeQuery(sql);

result1.next();

Date today = result1.getDate(1);


Any help would be appreciated.

View 4 Replies View Related

Call Getdate From Linked Server

May 12, 2008

Hello,

i need get value of getdate function on local and oon linked server by one select something like this:

select

getdate() 'locladate'
, [SERVER2SQL05_01, 9999].getdate() 'remotedate'

first problem i dont know in which database is getdate stored, second is it possible call function from linked server in select statement?


Thanks Jakub.

View 6 Replies View Related

Newbie Here With A Newbie Error - Getting Database ... Already Exists.

Feb 24, 2007

Hi there
I sorry if I have placed this query in the wrong place.
I'm getting to grips with ASP.net 2, slowly but surely! 
When i try to access my site which uses a Sql Server 2005 express DB i am receiving the following error:

Server Error in '/jarebu/site1' Application.


Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.Source Error:



An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:



[SqlException (0x80131904): Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.
Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735075
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
 
 This is the connection string that I am using:
 <connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;Initial Catalog=ASPNETDB;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
 
The database is definitly in the folder that the error message relates to.
What I'm finding confusing is that the connection string seems to be finding "aranga"s database.
Is it something daft?
 
Many thanks.
James 

View 1 Replies View Related

Linked Server Nolock Getdate Issue

Apr 14, 2008

Hi,

I am trying to retreive data using selet into query with nolock. Select query selects around 50,000 records from a linked server and inserting into my database. I have getdate() in my select list and it is returning different datetime in a single query which leads to a problem while taking distinct in later stages. Any info on why this nolock returns different datetime in a single getdate() statement will be a gr8 help.

Thanks in advance,
Senthil

View 4 Replies View Related

Select Convert(varchar(16), Getdate(), 101)+LEFT(REPLACE(convert(varchar, Getdate(), 108), ':', ''),4)

Sep 26, 2007



select convert(varchar(16), getdate(), 101)+LEFT(REPLACE(convert(varchar, getdate(), 108), ':', ''),4)

From above query I get

mmddyyyyhhmm

but it' s yyyy and hour can not be separated

04/12/200702:05

How can I separated the year and hour ?

Thanks
Daniel

View 2 Replies View Related

Calculate A Variable Average In SQL Server?

Jun 11, 2007

ok so i have this table:


Code:


Products_Sold
priceSold - money
itemsSold - int


An example of 4 rows on my table would be like this
$1400 80
$1500 85
$1560 82
$1700 81

to calculate the average of the price sold related to the number of sold items just have to do
Select avg(priceSold*itemsSold)

But sometimes i just want the average price of the first 100 sold items, so how can i make my query to just use the first 100 sold items?

in math it would be like this
average= ( (1400*80) + (1500*20) ) / 100

but if i wanted the first 200 it would be like this
average= ( (1400*80) + (1500*85) + (1560*35)) / 200

and if i wanted the first 300 would be like this
average= ( (1400*80) + (1500*85) + (1560*82) + (1700*53)) / 300

but of course the number i want will always be a variable which is less than the total of the products sold. So, how the heck do i program this query where the number of the items sold is variable and it will take the rows of the database depending on how many items were sold.

I hope i didnt wrote my explanation too confusing and that i can get any help from you guys. thank you a lot for the help and byye

View 1 Replies View Related

Calculate IOPs For Production Server?

Jan 13, 2014

We have SQl Server in the production with dozens databases that reside on a SAN in the RAID 1 configuration with SAS 10K disks. Few databases have a huge overload on the SAN (more writes than reads). As there are some performance issues we are considering new SAN.

Is there any way we can get average IOPs in this server? I tried to use PerMon but without success. I don't know if I can chose "Total" for Logical drives in PerMon for the counters? I read dozens of pages: use sqlio, take this counters, use that, but no straight way to calculate. I know that SAN could have the relevant info for IOPs but our old one doen't provide it.

how can I calculate it (without use these links or use this counters with no calculation procedure in the end)

View 7 Replies View Related

T-SQL (SS2K8) :: Expression To Calculate Age On Server

Apr 16, 2015

I have been trying to calculate age and the results either round the age up one year or down one year. I have tried CASE, DATEDIFF, FLOOR functions but nothing works.

View 3 Replies View Related

SQL Server 2008 :: How To Calculate Charge From Given Input Set

Mar 17, 2015

Work on sql server 2008 r2, need recursively charge amount calculation process.want to write an sp, In my sp I need to calculate head sum base on parameter head and given amount: Picture describe my db input set, from the input set I need to calculate total charge amount on given head,

Input set 1 HeadAmountIsPercentHead PercentGiven AmountCalculated AmountWorking Sequence
Utility10NoTotal400101
Sum10

Input Set 2 HeadAmountIsPercentHead PercentGiven AmountCalculated AmountWorking Sequence
Wages 10YesFinancial8001 2
Financial 10YesTotal 10 1
Sum11

[code]....

View 0 Replies View Related

SQL Server 2008 :: How To Calculate Date Time

Apr 9, 2015

My data is looks like this,

Date---------------------------------------A
2015-03-01 13:38:07.343----------------1
2015-03-01 14:04:04.460----------------1
2015-03-02 19:33:55.117----------------3
2015-03-02 19:33:55.117----------------4
2015-03-02 19:39:26.580----------------1

I want data looks like this

Date-------------------------------------------A
Day 1------------------------------------------2
Day 2------------------------------------------8

View 7 Replies View Related

SQL Server 2012 :: Calculate Total Between Two Columns

Sep 14, 2015

I have update schema and I upload image with my desire result.

CREATE TABLE #NONAMETABLE(
sinGroup NVARCHAR(10)
,column1 INT
,column2 int

[Code] .....

View 7 Replies View Related

SQL Server 2008 :: Calculate Number Of Days

Oct 8, 2015

I have client table which has client_id Eff_from and Eff_to columns.Eff_from and Eff_to are the dates that client is eligible for service. I need to know the average number of days from the day that he became not eligible and new eligibility date .

CLIENT_IDEFF_FREFF_TO
1001 12/24/200712/8/2010
100112/13/20123/26/2013
1001 5/27/20138/2/2013
10019/24/201310/30/2016

for expl days between
12/8/2010 and 12/13/2012
3/26/2013 and 5/27/2013
8/2/2013 and 9/24/2013

then AVG them.

View 3 Replies View Related

Newbie To Sql Server DTS...

Apr 9, 2005

Hi,
I am new to DTS.  I am also not sure whether this is the solution for my criteria. First my criteria. 
I have an Excel file where i would be capturing the data on a daily/weekly basis.  Now, i want to transfer the data to sqlserver at a regular interval let me say weekly once.  I want the record to append.  At later stages, planned to call from asp through asp.net.
Which is the best solution for to accomplish this task. 
Any good sample would be of great help.
Thanks in Advance to all.
 
Rgs
Ramu
 

View 1 Replies View Related

SQL SERVER 6.5 Newbie Please Help !!!!!!!!!!!!!!!!!!!!!!!!

Jan 3, 2000

Hi ,
My company will have a new application running On an NT Cluster .It has MICrosoft SQL 6.5 as its core element .I have been given Two Months to know Microsoft SQL 6.5 inside out .( commands configurationa and all ) .Please does anyone know any good books on Microsoft SQL 6.5 and knowing SQL thoroughly .
Please help
HAPPY NEW YEAR .
Thanks in anticipation .
Mibsun

View 3 Replies View Related

SQL Server 7 Newbie

Dec 21, 2004

I have a bunch of .sql files that will create a data model for me.
I've created a new database in my SQL Server 7 Enterprise Manager called Test.
How do i run this script? In part it looks like:

create table AGP_TYPES (
WL_AGP_TYPE VARCHAR2(4) not null,
WL_AGP_TYPE_DESC VARCHAR2(40),
constraint PK_AGP_TYPES primary key (WL_AGP_TYPE)
)
/


create unique index PK_AGP_TYPES on AGP_TYPES (
WL_AGP_TYPE ASC
)
/


create table ALARM_SYSTEMS (
WL_ALARM_TYPE VARCHAR2(4) not null,
WL_ALARM_TYPE_DESC VARCHAR2(40),
constraint PK_ALARM_SYSTEMS primary key (WL_ALARM_TYPE)
)
/


create unique index PK_ALARM_SYSTEMS on ALARM_SYSTEMS (
WL_ALARM_TYPE ASC
)
/

View 5 Replies View Related

SQL Server 2012 :: Calculate EndDate From Subsequent StartDate

Jul 28, 2014

Here is sample data I am working with:

Create table cattimelines (categoryID int, EffectiveDate datetime, CategoryValue varchar(11))

INSERT INTO cattimelines(categoryID, EffectiveDate, CategoryValue) VALUES(1000, '2014-01-01', 'A')
INSERT INTO cattimelines(categoryID, EffectiveDate, CategoryValue) VALUES(1000, '2014-02-01', 'B')
INSERT INTO cattimelines(categoryID, EffectiveDate, CategoryValue) VALUES(1000, '2014-04-01', 'C')
INSERT INTO cattimelines(categoryID, EffectiveDate, CategoryValue) VALUES(1000, '2014-07-01', 'A')

I need to calculates a term date for each record which will be 1 day before the effective date of any new record, thus:

CATEGORYIDEFFECTIVEDATETERMDATECATEGORYVALUE

10002014-01-012014-01-31A
10002014-02-012014-03-21B
10002014-04-012014-06-30C
10002014-07-01NULLA

View 3 Replies View Related

SQL Server 2012 :: Calculate Age Of Various Students In School System

Aug 31, 2014

In a sql server 2012 database, I have a field called date of birth that is stored in a tha that is stored in a datetime format. I need to determine the age of various students in the school system. Thus can you show me sql to that I can use to determine the a child is currently?

View 6 Replies View Related

SQL Server 2012 :: Calculate Customers Age And Value By Month And Year?

Sep 22, 2014

What's the best way to calculate a customers age and value by month and year?

I need to be able to calculate customer value by month and year, and then to calculate their age at each month in time. I've found a way of grouping sales by month and year that includes age for a particular contact like this:

select fh.contact_number
, concat(year(fh.transaction_date), '-', month(fh.transaction_date)) as transaction_month_year
, cast(fh.transaction_date as date) as transaction_date
, sum(fh.amount) as ttl_amount_in_month

[Code] .....

It seems to work, but any better way to achieve this?

View 1 Replies View Related

SQL Server 2012 :: How To Calculate Dates Difference In A Same Table

Sep 4, 2015

I have a table with appdt as first appointment date and the another record for the same customer# has follow up appointment.

Each customer is uniquely identified by a customer#

I need to find out if the customer came back after 200 days or more when the first appointment date was between jan12014 and Aug 31 2014. I am only interested in first follow up appointment after 30 days or more.

How can i do that in a query?

View 5 Replies View Related

Newbie SQL Server Question

May 18, 2007

Hello. I'm new to SQL server and I've run into a really basic issue. I'm working on a Visual Studio 2005 project and I have a SQL databse with a .BAK extension I need to use with the project. I've read online that I need to restore the database to a new database to work with SQL Server Express. Here's where I am lost. I can't find good instructions on how to restore the DB to a new one. Any help is really appreciated. Thanks.

View 3 Replies View Related

Newbie In SQL Server 2005

May 20, 2007

Good day. Is there any version of SQL server 2005(not include Express Edition) same as SQL server 2000 Personal edition ? I am planning to install new SQL server 2005 in my pc now. I am using Windows XP SP2 now. I tried to install to Entreprise Trial version, unfortunately it just works as client. Thank you in advance.


Regards,
Anson

View 3 Replies View Related

SQL Server Newbie Question

Jan 21, 2005

I have SQL Server 2000 installed on XP Pro and I am having problems connecting from an ASP.Net application.

The DB in question was exported from my laptop, which is running MSDE on Windows 2000. On that machine Trusted_Connection=true seems to work from the ASP.Net application whereas the SQL Server login that I set up does not.

Now that the DB has been imported to my XP machine, Trusted_Connection=true no longer seems to work. I am assuming that this may be related to the same problem I had when I was trying to use system logs - the ASPNET user does not have the same privileges on XP as it does on 2000.

In any case, I'm not too concerned at the moment how I connect, just as long as I am able. So, I again tried using the SQL login I had set up with no success.

(I added the SQL Login at the server level then I added it at the DB level and granted it public, db_datareader and db_datawriter access. Later, when that didn't work, I also granted it db_owner rights. Still no success. (BTW, I remembered to repeat these steps on my XP machine once I had imported the DB.))

Then I thought to try using 'sa'. To make sure I that remembered the sa password, I logged into Enterprise Manager (which, I assume uses Windows authentication) and changed it. Then, I went over to Web Data Administrator and tried to log in, using the SQL Login option, with sa and the password that I had just set - IT DIDN'T WORK.

Am I going mad, or is there something I'm missing?

Thanks
Martin

View 1 Replies View Related

SQL Server Newbie (Triggers)

Jul 31, 2000

Good afternoon one and all,

I am migrating a access dbase to SQL. I have two tables, the first is a buffer table that collects data from various sources, the second table is an indexed version of the first table (to eliminate duplicate records etc. etc.)

I am currently using the DTS packaage to transfer data between them, would a trigger be a better solution?

Thanks in advance for any and all help

Gurmi

View 2 Replies View Related

SQL Server Newbie (Triggers)

Jul 31, 2000

Good afternoon one and all,

I am migrating a access dbase to SQL. I have two tables, the first is a buffer table that collects data from various sources, the second table is an indexed version of the first table (to eliminate duplicate records etc. etc.)

I am currently using the DTS packaage to transfer data between them, would a trigger be a better solution?

Thanks in advance for any and all help

Gurmi

View 1 Replies View Related

Newbie Set Up And Testing Server

Mar 31, 2003

My previous experience is with php and MySQL.

I currently have Apache, MySQL and php running on my local machine to enable me to test php code on localhost

I've been asked by a colleague if I'll work on an SQL 2000 database they're having trouble with. They said they will provide Visual.net, SQL 2000 and any other software I need.

I'm completely in the dark on this, but have some starting questions:

To test my code, will I need to set up a sever on localhost?

Will I need other software than Visual.net and SQL 2000? I'm using DW MX for my web stuff.

Whre can I find a basic introduction to ASP / SQL 2000 in the form of a tutorial?

How fast does this combination run? The database has 25,000 rows and 6 columns. What would be a reasonal expect time for a result?

Any help appreciated

H

View 3 Replies View Related

Difference Between The MS SQL And The SQL Server? (was Newbie To MS SQL)

Nov 30, 2005

Hi,
I am totally a newbie to MS SQL. I have a question regarding the MS SQL: What is the difference between the MS SQL and the SQL Server? Is it the same? and what should be install for MS SQL on the server and the client side???

View 14 Replies View Related

SQL Server 2005 Newbie

Aug 7, 2006

I am relatively new to SQL Server and I have 2005. I am developing a database with an Access ADP frontend. The development is taking place on my laptop running a separate instance of SQL Server. I am trying to put the database on the production server and I am not sure how to proceed.

My laptop is not part of the network so I need to create a file and then import it on the SQL Server instance running on the production server. I thought I could do a backup and restore, but apparently that is not working.

Any help would be greatly appreciated.

View 4 Replies View Related

MS SQL Server - Newbie And Have Some Problems

Apr 21, 2004

hi to all,

i'm new at MS SQL Server,
i developed an application with MS SQL Server Developer Edtn. and i want to try it with a real server and clients

i tried to install it to WinXP Pro and it asks a domain and a user account, is theere a way to create a domain with winxp pro, or working with only server windows (2003 server, 2000 server etc.). If it is working with only server, is there a tutorial at internet to create a domain and users at windows (i lost lots of time to setup Ms SQL Server)
pls i need a tutorial, or a way to install MS SQL Server...

i want to install ms sql server to vmware machine,
i wonder how to make configurations to access my server on real machine and other machines that is on the network of real machine
(i think i must user pat, but how to make configurations is a big problem, but the biggest is installing sql server)

it is urgent pls help, i dont want to lose more time because i lost enough...

MeCeX

View 1 Replies View Related

Total Newbie To SQL Server

Sep 30, 2005

I'm in a slightly sticky situation. I recently got a job I interviewed for as a business analyst/programmer. I know quite a bit of VB 6.0 and SQL language, also enough access to build a decent database as a backend for my apps. I've recently received a 4 yr CIS degree, so I know a little about everything. I told them very clearly three times in the interview that I'd never built a SQL Server DB, but they must not have cared about that. They need someone who can program, do some DB work, and also do some business analysis. I was the best fit they could find.

After working with the group a few days, I figured out they need a data warehouse and marts to do some historical analysis, and eventually data mining and trend analysis, etc. I think they said they'd like to have that by the end of next year.

What I need now is one or two really great books to get started with, and a small synopsis on what I'm going to need as far as dev software and server specifics to get this thing off the ground. The first thing they would like to see is simply enough tables to dump data into from 4 or 5 different DBs, from which they can pull data for analysis whenever they need to do so. The total rows for this DB will be around 170mil, but with just a few measures in each row. Microsoft spreadsheet says I should expect about 5gig per year of data.

So I'm freaking out because I know ziltch about SQL Server, what tools and server set up I'm going to need, and the more I read, the less it sounds like "Oh it's not that big of a deal. It's easy", as a few friends told me.

Help!

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved