Search Results

Search found 355 results on 15 pages for 'getdate'.

Page 10/15 | < Previous Page | 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Logging into table in MS SQL trigger

    - by Martin
    I am coding MS SQL 2005 trigger. I want to make some logging during trigger execution, using INSERT statement into my log table. When there occurs error during execution, I want to raise error and cancel action that cause trigger execution, but not to lose log records. What is the best way to achieve this? Now my trigger logs everything except situation when there is error - because of ROLLBACK. RAISERROR statement is needed in order to inform calling program about error. Now, my error handling code looks like: if (@err = 1) begin INSERT INTO dbo.log(date, entry) SELECT getdate(), 'ERROR: ' + out from #output RAISERROR (@msg, 16, 1) rollback transaction return end

    Read the article

  • NHibernate 'IdentifierGenerationException' on an Update trigger

    - by Jan Jongboom
    In my database I have an id column defined as [autonumber] [int] IDENTITY(1,1) NOT NULL which is mapped in my .hbm.xml like: <id name="Id" column="autonumber" type="int"> <generator class="identity" /> </id> When calling session.Save() updates are successful committed to the database. When adding a versioning trigger I however get the error this id generator generates Int64, Int32, Int16 of type IdentifierGenerationException. The trigger is defined as: ALTER TRIGGER [dbo].[CatchUpdates_NVM_FDK_Kenmerken] ON [dbo].[NVM_FDK_Kenmerken] INSTEAD OF UPDATE AS BEGIN SET NOCOUNT ON UPDATE NVM_FDK_Kenmerken SET idIsActive = 0 WHERE internalId IN (SELECT internalId FROM INSERTED) INSERT INTO dbo.NVM_FDK_Kenmerken ( vestigingNummer , internalId , someOtherColumns, dateInserted, idIsActive ) SELECT vestigingNummer, internalId, someOtherColumns, GETDATE(), 1 FROM INSERTED END What am I doing wrong here? When doing manual updates everything works just fine and as expected.

    Read the article

  • Data Access from single table in sql server 2005 is too slow

    - by Muhammad Kashif Nadeem
    Following is the script of table. Accessing data from this table is too slow. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Emails]( [id] [int] IDENTITY(1,1) NOT NULL, [datecreated] [datetime] NULL CONSTRAINT [DF_Emails_datecreated] DEFAULT (getdate()), [UID] [nvarchar](250) COLLATE Latin1_General_CI_AS NULL, [From] [nvarchar](100) COLLATE Latin1_General_CI_AS NULL, [To] [nvarchar](100) COLLATE Latin1_General_CI_AS NULL, [Subject] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [Body] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [HTML] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [AttachmentCount] [int] NULL, [Dated] [datetime] NULL ) ON [PRIMARY] Following query takes 50 seconds to fetch data. select id, datecreated, UID, [From], [To], Subject, AttachmentCount, Dated from emails If I include Body and Html in select then time is event worse. indexes are on: id unique clustered From Non unique non clustered To Non unique non clustered Tabls has currently 180000+ records. There might be 100,000 records each month so this will become more slow as time will pass. Does splitting data into two table will solve the problem? What other indexes should be there?

    Read the article

  • DNS Lookup in simple C#/asp.net ajax call is extremely slow

    - by Ryan
    I'm running this out of the VS 2008 debugger on Windows 7, running .Net 3.5. The idea was to make all ajax requests with jQuery only, rather than .net, following some tutorials online. Default.aspx - HTML page, jquery triggers method in Default.aspx.cs http://pastebin.com/pxBvKA2H Default.aspx.cs - C# Webform, just defines a GetDate fuction, which only returns a string for now (trying to eliminate any possible issues) (can only post one hyperlink...) pastebin.com/pnHn50hu The ajax query takes longer than it should. Profiling with firebug revealed that it took 1.03 ms. 1s DNS Lookup | 26ms Waiting | 1ms Receiving EDIT: It continues to take the same set of times if you continue to click and resubmit the request. Is there anything I can do to cut down on the DNS Lookup time / what did I do wrong? Thanks for any help.

    Read the article

  • Getting a value from a row at particular time

    - by Swetha Bindu
    I had a row in my database: starttime:4/6/2012 2:00pm, Endtime:31/12/9999, name:"swetha", status:"open"..... When I update this row I changed the starttime to the current time (getdate()) and have no issues. I am running a Windows Service each day at 1am to modify a value in the row. I would like to know the status of my row at 4/6/2012 11:59 pm when my service runs. There is no need to do an update at 4/6/2012 11:59 pm and the last update may be at any time of the day however my requirement is to get the status value at 4/6/2012 11:59 pm. I would like to have the query in SQL Server 2008. Can anyone please help me to find a solution?

    Read the article

  • Custom SQL function for NHibernate dialect

    - by Kristoffer Ahl
    I want to be able to call a custom function called "recent_date" as part of my HQL. Like this: [Date] >= recent_date() I created a new dialect, inheriting from MsSql2000Dialect and specified the dialect for my configuration. public class NordicMsSql2000Dialect : MsSql2000Dialect { public NordicMsSql2000Dialect() { RegisterFunction( "recent_date", new SQLFunctionTemplate( NHibernateUtil.Date, "dateadd(day, -15, getdate())" ) ); } } var configuration = Fluently.Configure() .Database( MsSqlConfiguration.MsSql2000 .ConnectionString(c => .... ) .Cache(c => c.UseQueryCache().ProviderClass<HashtableCacheProvider>()) .Dialect<NordicMsSql2000Dialect>() ) .Mappings(m => ....) .BuildConfiguration(); When calling recent_date() I get the following error: System.Data.SqlClient.SqlException: 'recent_date' is not a recognized function name I'm using it in a where statement for a HasMany-mapping like below. HasMany(x => x.RecentValues) .Access.CamelCaseField(Prefix.Underscore) .Cascade.SaveUpdate() .Where("Date >= recent_date()"); What am I missing here?

    Read the article

  • Auto-generated values for columns in database

    - by Jamal
    Is it a good practice to initialize columns that we can know their values in database, for example identity columns of type unique identifier can have a default value (NEWID()), or columns that shows the record create date can have a default value (GETDATE()). Should I go through all my tables and do this whereever I am sure that I won't need to assign the value manually and the Auto-generated value is correct. I am also thinking about using linq-to-sql classes and setting the "Auto Generated Value" property of these columns to true. Maybe this is what everybody already knows or maybe I am asking a question about a fundamental issue, if so please tell me.

    Read the article

  • Month to Date in SQL Server 2008

    - by Aaron Smith
    Hopefully this will be an easy one to answer. I am working on a table that requires MTD data. One of our SQL guys told me to use MONTH (@monthtodate)= 11 Where @monthtodate is set to GetDate() in the parameter list in SQL Server Management Studio. So in "theory", he says, it should select the month (11) and then get today and return all the requested data in between those two dates. But I'm thinking this isn't correct. In looking at my data I'm starting to think that It's just returning data for the whole month of November instead of just MTD. I guess, technically, anything that has 0 won't be calculated. However that just means it's poorly written code correct? In your opinions, would this be the better way to return MTD data: production_date <= @today and Production_Date >= DATEADD(mm, DATEDIFF(mm, 0, @today), 0) Thanks in advance everyone!

    Read the article

  • MSSQL - Select one random record not showing duplicates

    - by Lukes123
    I have two tables, events and photos, which relate together via the 'Event_ID' column. I wish to select ONE random photo from each event and display them. How can I do this? I have the following which displays all the photos which are associated. How can I limit it to one per event? SELECT Photos.Photo_Id, Photos.Photo_Path, Photos.Event_Id, Events.Event_Title, Events.Event_StartDate, Events.Event_EndDate FROM Photos, Events WHERE Photos.Event_Id = Events.Event_Id AND Events.Event_EndDate < GETDATE() AND Events.Event_EndDate IS NOT NULL AND Events.Event_StartDate IS NOT NULL ORDER BY NEWID() Thanks Luke Stratton

    Read the article

  • Is there a consolidated way of writing several prototype functions for a single object?

    - by Christopher Altman
    I have about eight prototype functions for the Date object. I would like to avoid repeating Date.prototype. Is there a consolidated way of writing several prototype functions for a single object? I tried this to no avail: Date.prototype = { getMonthText: function(date){ var month = this.getMonth(); if(month==12) month = 0; return ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'][month]; }, getDaysInMonth: function(date){ return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate(); } };

    Read the article

  • how to insert based on the date

    - by Gaolai Peng
    I have a table table1 (account, last_contact_date, insert_date), account and last_contact_date are primary keys. The insert_date is set with the time the recored being added by calling getdate(). I also have a temporary table #temp(account, last_contact_date) which I use to update the table1. Here are sample data: table1 account last_contact_date insert_date 1 2012-09-01 2012-09-28 2 2012-09-01 2012-09-28 3 2012-09-01 2012-09-28 #temp account last_contact_date 1 2012-09-27 2 2012-09-27 3 2012-08-01 The result table depends on the inserting date. If the date is 2012-09-28, the result will be table1 account last_contact_date insert_date 1 2012-09-27 2012-09-28 2 2012-09-27 2012-09-28 3 2012-09-01 2012-09-28 If the date is 2012-09-29, the result will be table1 account last_contact_date insert_date 1 2012-09-01 2012-09-28 2 2012-09-01 2012-09-28 3 2012-09-01 2012-09-28 1 2012-09-27 2012-09-29 2 2012-09-27 2012-09-29 Basically the rule is (1) if the inserting date is the same day, i will pick the lastest last_contact_date, otherwise, (2) if the last_contact_date is later than the current last_contact_date, I will insert a new one. How do I write a query for this insert?

    Read the article

  • SQL Server 2008 vs 2005 udf xml perfomance problem.

    - by user344495
    Ok we have a simple udf that takes a XML integer list and returns a table: CREATE FUNCTION [dbo].[udfParseXmlListOfInt] ( @ItemListXml XML (dbo.xsdListOfInteger) ) RETURNS TABLE AS RETURN ( --- parses the XML and returns it as an int table --- SELECT ListItems.ID.value('.','INT') AS KeyValue FROM @ItemListXml.nodes('//list/item') AS ListItems(ID) ) In a stored procedure we create a temp table using this UDF INSERT INTO @JobTable (JobNumber, JobSchedID, JobBatID, StoreID, CustID, CustDivID, BatchStartDate, BatchEndDate, UnavailableFrom) SELECT JOB.JobNumber, JOB.JobSchedID, ISNULL(JOB.JobBatID,0), STO.StoreID, STO.CustID, ISNULL(STO.CustDivID,0), AVL.StartDate, AVL.EndDate, ISNULL(AVL.StartDate, DATEADD(day, -8, GETDATE())) FROM dbo.udfParseXmlListOfInt(@JobNumberList) TMP INNER JOIN dbo.JobSchedule JOB ON (JOB.JobNumber = TMP.KeyValue) INNER JOIN dbo.Store STO ON (STO.StoreID = JOB.StoreID) INNER JOIN dbo.JobSchedEvent EVT ON (EVT.JobSchedID = JOB.JobSchedID AND EVT.IsPrimary = 1) LEFT OUTER JOIN dbo.Availability AVL ON (AVL.AvailTypID = 5 AND AVL.RowID = JOB.JobBatID) ORDER BY JOB.JobSchedID; For a simple list of 10 JobNumbers in SQL2005 this returns in less than 1 second, in 2008 this run against the exact same data returns in 7 min. This is on a much faster machine with more memory. Any ideas?

    Read the article

  • SQL Trigger dont works...

    - by Gabotron
    Is there a way in which a Trigger is not fired? We have this situation: We have a table and there are rows that are been deleted. We need to know who and/or when these row are deleted. We create this trigger: ALTER TRIGGER [dbo].[AUDITdel_nit] ON [dbo].[Client] FOR DELETE AS Insert into AUDIT select 'Delete', getdate(), 'Row Deleted', SYSTEM_USER, host_name(), (select 'ID Client: ' + convert(varchar(12),Id) from deleted), 'Client' ,APP_NAME() We made somte test: deleting rows vis stored procedures and the deleted rows appears in our AUDIT table. But suddenly today we found a row deleted that dont appears in the AUDIT table... Any idea how it can be done?

    Read the article

  • Automatic open Colorbox modal window

    - by user1631168
    I'm using the Colorbox module in Drupal 7. I'm opening an external website. I can make it work with a link. Click here, then click the "colorbox popup" link at the bottom, middle column. The client would like this to open automatically when the page opens. I've created a block and added the following code (from the colorbox site). <script type="text/javascript"> // Display a welcome message on first visit, and set a cookie that expires in 30 days: if (document.cookie.indexOf('visited=true') === -1) { var expires = new Date(); expires.setDate(expires.getDate()+30); document.cookie = "visited=true; expires="+expires.toUTCString(); jQuery.colorbox({html:"http://join.raretearepublic.com/popup/", width:887, height:638}); } </script> But it does not work. Any help would be greatly appreciated.

    Read the article

  • Loading an XML file with todays date in the filename... need to fallback to old file if one with tod

    - by arala22
    So here is my question. Using javascript/jQuery I am currently loading in an XML file that has a file name such as carousel_large_2010-06-08.xml.. the way I am doing it is checked for todays date then grabbing a file that has that date in the filename... the issue is sometimes they wont be uploading a new file for a given day so it needs to fallback to a older date that exists.. Wondering how to do it? Here is my code: // set date for xml file var currentTime = new Date(), month = currentTime.getMonth() + 1, day = currentTime.getDate(), year = currentTime.getFullYear(); if(month.toString().length == 1){ month = '0'+month.toString(); } if(day.toString().length == 1){ day = '0'+day.toString(); } var dateObject = year+"-"+month+"-"+day; // start magic $jq.ajax({ type: "GET", url: "_xml/carousel/home/carousel_large_"+dateObject+".xml", dataType: "xml", success: HPCarousels.heroCarousel.parseXML, error: function(){ alert('Error Loading XML Content'); } });

    Read the article

  • SQL Server - Select one random record not showing duplicates

    - by Lukes123
    I have two tables, events and photos, which relate together via the 'Event_ID' column. I wish to select ONE random photo from each event and display them. How can I do this? I have the following which displays all the photos which are associated. How can I limit it to one per event? SELECT Photos.Photo_Id, Photos.Photo_Path, Photos.Event_Id, Events.Event_Title, Events.Event_StartDate, Events.Event_EndDate FROM Photos, Events WHERE Photos.Event_Id = Events.Event_Id AND Events.Event_EndDate < GETDATE() AND Events.Event_EndDate IS NOT NULL AND Events.Event_StartDate IS NOT NULL ORDER BY NEWID() Thanks Luke Stratton

    Read the article

  • Twitter search for my recent tweets

    - by ravenspoint
    Has twitter search stopped supporting this: from:username since:2010-05-01 It used to work! The reason I care is I use the following javascript to display recent tweets on my webpage var username = '...' var od = new Date(); od.setMilliseconds( od.getMilliseconds() - 518400000 ); var month = od.getMonth() + 1 if (month<10) month = ('0'+month) var day = od.getDate() if (day<10) day = ('0'+day) var year = od.getFullYear() var sd = (year + '-' + month + '-' + day) document.write( sd ) new TWTR.Widget({ search: 'from:' + username + ' since:' + sd, This has worked for about a year, but recently stopped.

    Read the article

  • sql query with alias name

    - by Ranjana
    i have a table with this columns--- Or orgid ispaid validity noofthingstoTake 1 yes 2010-06-05 20 2 yes 2010-06-09 7 i have used this query(to join two more tableS): select distinct B.RequirementID,A.OrganizationID from Organization A,RequirementsDetailsforOrganization B,validityorgdet F where A.OrganizationID=B.OrganizationID and F.orgid=A.OrganizationID and F.ispaid=1 and F.validity>=GETDATE() and F.noofthingstoTake> ?? but i dont know how to check the (noofthingstaken) over here. it should not exceed 20. im passing this query from my code behind page to the Sql. how to get the query excute to check it should not exceed the noofthingstaken pls help me out....????

    Read the article

  • foreign key and index issue

    - by George2
    Hello everyone, I am using SQL Server 2008 Enterprise. I have a table and one of its column is referring to another column in another table (in the same database) as foreign key, here is the related SQL statement, in more details, column [AnotherID] in table [Foo] refers to another table [Goo]'s column [GID] as foreign key. [GID] is primary key and clustered index on table [Goo]. My question is, in this way, if I do not create index on [AnotherID] column on [Foo] explicitly, will there be an index created automatically for [AnotherID] column on [Foo] -- because its foreign key reference column [GID] on table [Goo] already has primary clustered key index? CREATE TABLE [dbo].[Foo]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [AnotherID] [int] NULL, [InsertTime] [datetime] NULL CONSTRAINT DEFAULT (getdate()), CONSTRAINT [PK_Foo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] ALTER TABLE [dbo].[Foo] WITH CHECK ADD CONSTRAINT [FK_Foo] FOREIGN KEY([Goo]) REFERENCES [dbo].[Goo] ([GID]) ALTER TABLE [dbo].[Foo] CHECK CONSTRAINT [FK_Foo] thanks in advance, George

    Read the article

  • Help with dates in Android

    - by SamRowley
    Hi guys, Looking for a bit of help with taking a dat from a DatePicker Widget and storing it in an sqlite database within the app. I have the following code: java.util.Date utilDate = null; String y = Integer.toString(date.getDayOfMonth()) + "/" + (date.getMonth()+1) + "/" + Integer.toString(date.getYear()); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyy"); utilDate = formatter.parse(y); java.sql.Date z = new java.sql.Date(utilDate.getDate()); x = z.toString(); Log.v("The date: ", x); } Where date is the DatePicker widget. If I output the utilDate variable (i.e. the Java version of date) using logCat it seems to work fine and gives me a format like: Tue Jan 04 00:00:00 GMT 2011 which I am expecting but using the code above to get the sql version of the date, it always gives me the date 1970-01-01. I'm pretty sure the solution is very simple but I just can't see it.

    Read the article

  • problem adding a where clause to a T-sql LEFT OUTER JOIN query

    - by Nickson
    SELECT TOP (100) PERCENT dbo.EmployeeInfo.id, MIN(dbo.EmployeeInfo.EmpNo) AS EmpNo, SUM(dbo.LeaveApplications.DaysAuthorised) AS DaysTaken FROM dbo.EmployeeInfo LEFT OUTER JOIN dbo.LeaveApplications ON dbo.EmployeeInfo.id = dbo.LeaveApplications.EmployeeID WHERE (YEAR(dbo.LeaveApplications.ApplicationDate) = YEAR(GETDATE())) GROUP BY dbo.EmployeeInfo.id, dbo.EmployeeMaster.EmpNo ORDER BY DaysTaken DESC The basic functionality i want is to retrieve all records in table dbo.EmployeeInfo irrespective of whether a corresponding record exists in table dbo.LeaveApplications. If a row in EmployeeInfo has no related row in LeaveApplications, i want to return its SUM(dbo.LeaveApplications.DaysAuthorised) AS DaysTaken column as NULL or may be even put a 0. With the above query, if i remove the where condition, am able to achieve what i want, but problem is i also want to return related rows from LeaveApplication only if ApplicationDate is in the current year. Now with the where condition added, am only able to get rows from EmployeeInfo only if they have corresponding rows in LeaveApplications yet i just wanted rows all in EmployeeInfo

    Read the article

  • Am i doing it right ? - jquery ques ...

    - by Sakti
    $(document).ready(function(){ var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var month = new array("January","February","March","April","May","June","July","August","September","October","November","December"); var mon; mon = month(m); var today = m+"/"+d+"/"+y $('#calendar').append('<div id="today">Today is'+' '+mon+'/'+d+'/'+y+'.'); });

    Read the article

  • How might you unobtrusively enhance the jQuery Datepicker class?

    - by Teflon Ted
    You can pass special strings into jQuery's Datepicker class setDate() method like "+7" which will be translated into "7 days from today": http://docs.jquery.com/UI/Datepicker#method-setDate But you can't get that "+7" back out. When you call getDate() you get the calculated resulting date. I have a use case where I need to pull out the special string "+7" for propagation. One chunk of code is passing a special string into the Datepicker and passing the Datepicker over to another chunk of code which pulls out the date, but the latter sometimes needs to know the special string rather than the calculated date. So I need to enhance the Datepicker tool to (a) store the special code internally and (b) expose it via a method like getOriginallyPassedInDate() or some such. I'm not a jQuery/Javascript ninja so I could really use some guidance on how I might preferably-unobtrusively add the necessary functionality to the Datepicker class, the way you might monkey-patch an object in Ruby I'm guessing.

    Read the article

  • Snapshot on, still deadlocks, ROWLOCK

    - by Patto
    I turned snapshot isolation on in my database using the following code ALTER DATABASE MyDatabase SET ALLOW_SNAPSHOT_ISOLATION ON ALTER DATABASE MyDatabase SET READ_COMMITTED_SNAPSHOT ON and got rid off lots of deadlocks. But my database still produces deadlocks, when I need to run a script every hour to clean up 100,000+ rows. Is there a way I can avoid deadlocks in my cleanup script, do I need to set ROWLOCK specifically in that query? Is there a way to increase the number of row level locks that a database uses? How are locks promoted? From row level to page level to table level? My delete script is rather simple: delete statvalue from statValue, (select dateadd(minute,-60, getdate()) as cutoff_date) cd where temporaryStat = 1 and entrydate < cutoff_date Right now I am looking for quick solution, but a long term solution would be even nicer. Thanks a lot, Patrikc

    Read the article

  • Would like help with LOGON Trigger

    - by Risho
    I've created a logon trigger in MS SQL that needs to check dm_exec_sessions for a login. This login is the user listed in the connection string and has owner right to the database. If the login is verified, I need it to update a specific table and send an email. So far I've done just the following piece and it disabled my web site. The error I get is: "Logon failed for login 'dev' due to trigger execution. Changed database context to 'mydatabase'. Changed language setting to us_english." Any idea what I did wrong? Thanks, Risho CREATE TRIGGER TDY_Assets_Notification ON ALL SERVER WITH EXECUTE AS 'dev' FOR LOGON AS BEGIN IF ORIGINAL_LOGIN()='dev' AND (SELECT COUNT(*) FROM sys.dm_exec_sessions WHERE is_user_process = 1 AND original_login_name = 'dev') > 1 UPDATE Assets_TDY SET Suspense = 1, Warning = 1 WHERE (Date_Returned IS NULL) AND (GETDATE() >= DATEADD(day, 3, Date_Return)) END

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15  | Next Page >