Search Results

Search found 28900 results on 1156 pages for 'sql 2005'.

Page 80/1156 | < Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >

  • T-SQL query with date range

    - by Moo
    Hi, I have a fairly weird 'bug' with a simple query, and I vaguely remember reading the reason for it somewhere a long time ago but would love someone to refresh my memory. The table is a basic ID, Datetime table. The query is: select ID, Datetime from Table where Datetime <= '2010-03-31 23:59:59' The problem is that the query results include results where the Datetime is '2010-04-01 00:00:00'. The next day. Which it shouldn't. Anyone? Cheers Moo

    Read the article

  • UNIQUE Constraints in SQL (MS-SQL)

    - by rockbala
    Why are UNIQUE Constraints needed in database ? Can you provide any examples ? Primary Key is UNIQUE by default... Understandable as they are referred in other tables as Foreign keys... relation is needed to connect them for rdbms platform... but why would one refer to other columns as UNIQUE, what is benefit of doing so ?)

    Read the article

  • Better way to write this SQL

    - by AngryHacker
    I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int) I am trying to get the latest ID_AdvancedRatePlan based on a ID_Hearing. By latest I mean with the largest ID_ARDebitDetail. I have this query and it works fine. select ID_AdvancedRatePlan from ARDebitDetails where ID_Hearing = 135878 and ID_ARDebitDetail = ( select max(ID_ARDebitDetail) from ARDebitDetails where ID_AdvancedRatePlan > 0 and ID_Hearing = 135878 ) However, it just looks ugly and smells bad. Is there a way to rewrite it in a more concise manner?

    Read the article

  • SQL Server: How do I delimit this data?

    - by codingguy3000
    declare @mydata nvarchar(4000) set @mydata = '36|0, 77|5, 132|61' I have this data that I need to get into a table. So for Row1 columnA would be 36 and columnB would be 0. For Row2 columnA would be 77 and columnB would be 5 etc. What is the best way to do this? Thanks

    Read the article

  • Getting Null value Of variable in sql server

    - by Neo
    Strange situation In a trigger i assign a column value to variable but gives exception while inserting into other table using that variable. e.g select @srNO=A.SrNo from A where id=123; insert into B (SRNO) values (@srNo) // here it gives null I run above select query in query pane it works fine but in trigger it gives me null any suggestions

    Read the article

  • UNIQUE Constraints in SQL (SQL Server)

    - by rockbala
    Why are UNIQUE Constraints needed in database ? Can you provide any examples ? Primary Key is UNIQUE by default... Understandable as they are referred in other tables as Foreign keys... relation is needed to connect them for rdbms platform... but why would one refer to other columns as UNIQUE, what is benefit of doing so ?)

    Read the article

  • Remove and Replace multiple chars ( spaces, hyphen, brackets, period) from string in sql

    - by Muhammad Kashif Nadeem
    +39 235 6595750 19874624611 +44 (0)181 446 5697 +431 6078115-2730 +1 617 358 5128 +48.40.23755432 +44 1691 872 410 07825 893217 0138 988 1649 (415) 706 2001 00 44 (0) 20 7660 4650 (765) 959-1504 07731 508 486 please reply by email dont have one +447769146971 Please see the above given phone numbers. I need to replace all spaces, hyphen, period, brackets and leading 0 etc from these numbers. I need this format +447469186974 If number has leading plus sign then don't replace it otherwise I have to concatenate + sign with it. E.G +39 235 6595750 in this number I just need to remove spaces. +44 (0)181 446 5697 in this i need to removes spaces and brackets and 0 in between brackets i.e (0) 07825 893217 in this I need to replace leading 0 with + sign and remove spaces (415) 706 2001 in this replace '(' with + sign and remove ')' and spaces. 'please reply by email' This is the entry in phone number field and I just need to ignore this. +48.40.23755432 Remove period in phone number (765) 959-1504 Remove brackets and spaces and hyphen and add + sign in front of number. 7798724250 just need to add + sign in front of number 00 44 (0) 20 7660-4650 Need to remove leading 0 I.E '00' remove spaces and brackets and 0 in between brackets and hyphen and add + sign in front of number Only leading '0' will be replaced not anyother occourence of '0' The desired result is +447769146971 Should I use nested REPLACE, CHARINDES, PATINDES for each char I want to replace? Thanks.

    Read the article

  • Specifying schema for temporary tables

    - by Tom Hunter
    I'm used to seeing temporary tables created with just the hash/number symbol, like this: CREATE TABLE #Test ( [Id] INT ) However, I've recently come across stored procedure code that specifies the schema name when creating temporary tables, for example: CREATE TABLE [dbo].[#Test] ( [Id] INT ) Is there any reason why you would want to do this? If you're only specifying the user's default schema, does it make any difference? Does this refer to the [dbo] schema in the local database or the tempdb database?

    Read the article

  • Picking Random Names

    - by Jasl
    I saw an interesting post sometime back but with no solution. Trying luck here: There is a table which contain 10 names (U1, U2, U3..and so on). I have to choose 5 names everyday, and display one as the Editor and 4 as Contributors While selecting the random names, I have to also consider that if one user is selected as Editor, he cannot become editor again till everyone got their chance. The output should look similar to the following: Editor Cont1 Cont2 Cont3 Cont4 20-Jun U1 U8 U9 U3 U4 21-Jun U7 U2 U5 U6 U10 22-Jun U3 U4 U9 U2 U8 23-Jun U4 U8 U3 U5 U2 and so on..

    Read the article

  • How to convert row data into columns in SQL

    - by iHeartDucks
    Hi, I have looked into pivot but I think it requires an aggregate function which I do not need (I think). The result of my query is this Name Property Name PropertyValue ---------- ---------- ---------- lorem Work Phone 000.111.2020 ipsum Email [email protected] To Name Work Phone Email ---------- ---------- ---------- lorem 000.111.2020 [email protected] ipsum 001.101.2010 [email protected] I don't think I should use pivot here because I don't need to aggregate anything, I just want the row data to become a column.

    Read the article

  • regarding like query operator

    - by stackoverflowuser
    Hi For the below data (well..there are many more nodes in the team foundation server table which i need to refer to..below is just a sample) Nodes ------------------------ \node1\node2\node3\ \node1\node2\node5\ \node1\node2\node3\node4 I was wondering if i can apply something like (below query does not give the required results) select * from table_a where nodes like '\node1\node2\%\' to get the below data \node1\node2\node3\ \node1\node2\node5\ and something like (below does not give the required results) select * from table_a where nodes like '\node1\node2\%\%\' to get \node1\node2\node3\ \node1\node2\node5\ \node1\node2\node3\node4 Can the above be done with like operator? Pls. suggest. Thanks

    Read the article

  • SQL Operators as text in where clause

    - by suggy1982
    I have the following table, which is used for storing bandings. The table is maintained via a web frontend. CREATE TABLE [dbo].[Banding]( [BandingID] [int] IDENTITY(1,1) NOT NULL, [ValueLowerLimitOperator] [varchar](10) NULL, [ValueLowerLimit] [decimal](9, 2) NULL, [ValueUpperLimitOperator] [varchar](10) NULL, [ValueUpperLimit] [decimal](9, 2) NULL, [VolumeLowerLimitOperator] [varchar](10) NULL The operator fields store values such as < = <=. I want to get to a position where I can use the operators values stored in the table in a case statement in a where clause. Like this. SELECT * FROM table WHERE CASE ValueLowerLimitOperator WHEN '<' THEN VALUE < X WHEN '>' THEN VALUE > X END rather than having to write mutiple case or if statements for each permutation. Does anyone have any suggestions how I can decode the operators values stored in the table as part of my query and then use them in a case/where statement?

    Read the article

  • Optimal way to convert to date

    - by IMHO
    I have legacy system where all date fields are maintained in YMD format. Example: 20101123 this is date: 11/23/2010 I'm looking for most optimal way to convert from number to date field. Here is what I came up with: declare @ymd int set @ymd = 20101122 select @ymd, convert(datetime, cast(@ymd as varchar(100)), 112) This is pretty good solution but I'm wandering if someone has better way doing it

    Read the article

  • How to index a table with a Type 2 slowly changing dimension for optimal performance

    - by The Lazy DBA
    Suppose you have a table with a Type 2 slowly-changing dimension. Let's express this table as follows, with the following columns: * [Key] * [Value1] * ... * [ValueN] * [StartDate] * [ExpiryDate] In this example, let's suppose that [StartDate] is effectively the date in which the values for a given [Key] become known to the system. So our primary key would be composed of both [StartDate] and [Key]. When a new set of values arrives for a given [Key], we assign [ExpiryDate] to some pre-defined high surrogate value such as '12/31/9999'. We then set the existing "most recent" records for that [Key] to have an [ExpiryDate] that is equal to the [StartDate] of the new value. A simple update based on a join. So if we always wanted to get the most recent records for a given [Key], we know we could create a clustered index that is: * [ExpiryDate] ASC * [Key] ASC Although the keyspace may be very wide (say, a million keys), we can minimize the number of pages between reads by initially ordering them by [ExpiryDate]. And since we know the most recent record for a given key will always have an [ExpiryDate] of '12/31/9999', we can use that to our advantage. However... what if we want to get a point-in-time snapshot of all [Key]s at a given time? Theoretically, the entirety of the keyspace isn't all being updated at the same time. Therefore for a given point-in-time, the window between [StartDate] and [ExpiryDate] is variable, so ordering by either [StartDate] or [ExpiryDate] would never yield a result in which all the records you're looking for are contiguous. Granted, you can immediately throw out all records in which the [StartDate] is greater than your defined point-in-time. In essence, in a typical RDBMS, what indexing strategy affords the best way to minimize the number of reads to retrieve the values for all keys for a given point-in-time? I realize I can at least maximize IO by partitioning the table by [Key], however this certainly isn't ideal. Alternatively, is there a different type of slowly-changing-dimension that solves this problem in a more performant manner?

    Read the article

  • INSERT statement conflicted with the FOREIGN KEY constraint

    - by SmartestVEGA
    I am getting the following error. Could you please help me in ? Msg 547, Level 16, State 0, Line 1 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Sup_Item_Sup_Item_Cat". The conflict occurred in database "dev_bo", table "dbo.Sup_Item_Cat". The statement has been terminated. insert into sup_item (supplier_id,sup_item_id,name,sup_item_cat_id,status_code,last_modified_user_id,last_modified_timestamp,client_id) values(10162425,10,'jaiso','123123','a','12','2010-12-12','1062425') the last coulum "client_id" i am getting the conflict. I tried to put the value which already exists in the dbo.Sup_Item_Cat to the column corresponding to the sup_item.. but no joy :-(

    Read the article

  • SQL Query with conditional JOIN

    - by mariki
    The scenario: Table1 CatId|Name|Description Table2 ItId|Title|Date|CatId (foreign key) I want to return all rows from Table1 and Title,Date from Table2, where The returned from Table 2 must be the Latest one by the date column. (in second table there many items with same CatId and I need just the latest) I have 2 queries but can't merge them together: Query 1: SELECT Table1.Name, Table1.Description, Table2.Title, Table2.Date FROM Table1 LEFT JOIN Table2 ON Table1.CatId=Table2.CatId Query2: SELECT TOP 1 Table2.Title, Table2.Date FROM Table2 WHERE Table2.CatId = @inputParam ORDER BY Table2.Date DESC

    Read the article

  • Most optimal way to convert to date

    - by IMHO
    I have legacy system where all date fields are maintained in YMD format. Example: 20101123 this is date: 11/23/2010 I'm looking for most optimal way to convert from number to date field. Here is what I came up with: declare @ymd int set @ymd = 20101122 select @ymd, convert(datetime, cast(@ymd as varchar(100)), 112) This is pretty good solution but I'm wandering if someone has better way doing it

    Read the article

  • Displaying same record twice- SQL Reporting Services

    - by RyanW
    Ok, here's the situation: I need to display the same record in two different sections. stupid i know, but here's why. The Report I am building is grouped by one Field, called Day. Each record has date/times, an expected arrival date time, and an expected departure date/time. so, at this point we have something like this: Day..............Arrival Time..................Departure Time 18/5.............18/5 9.00am.........19/5 11.00am The boss only wants to show times that relate to the current day in the arrive/depart coloumns (easy enough with expressions), which ends up like this: Day..............Arrival Time..................Departure Time 18/5..............9.00am.........................- the next thing he wants is to display the departing time in the correct day 'group', but as you can imagine as soon as you move to the next row, well you move to the next row of the table. So the question is: is there anyway to display the same record on multiple coloumns? Have i missed something or have i got an unsolvable problem? NOTE: this is not the only data in my table either. there is (for example) a name coloumn which also needs to be displayed on both days.

    Read the article

  • Using "CASE" in Where clause to choose various column harm the performance

    - by zivgabo
    I have query which needs to be dynamic on some of the columns, meaning I get a parameter and according its value I decide which column to fetch in my Where clause. I've implemented this request using "CASE" expression: (CASE @isArrivalTime WHEN 1 THEN ArrivalTime ELSE PickedupTime END) >= DATEADD(mi, -@TZOffsetInMins, @sTime) AND (CASE @isArrivalTime WHEN 1 THEN ArrivalTime ELSE PickedupTime END) < DATEADD(mi, -@TZOffsetInMins, @fTime) If @isArrivalTime = 1 then chose ArrivalTime column else chose PickedupTime column. I have a clustered index on ArrivalTime and nonclustered index on PickedupTime. I've noticed that when I'm using this query (with @isArrivalTime = 1), my performance is a lot worse comparing to only using ArrivalTime. Maybe the query optimizer can't use\choose the index properly in this way? I compared the execution plans an noticed that when I'm using the CASE 32% of the time is being wasted on the index scan, but when I didn't use the CASE(just usedArrivalTime`) only 3% were wasted on this index scan. Anyone know the reason for this?

    Read the article

  • How do I use BCP or Sql Server Management Studio to get BLOB data our of Sql Server?

    - by Eric
    I'm sorry if this question has been asked already, but I couldn't find it anywhere. I have a table that stores files as BLOBS. The column that holds the file is an image datatype. I would like to be able to extract the binary data out of the column and turn it in to an actual file. I would ideally like to be able to do this with BCP or management studio if possible. I have tried BCP, but for some reason when I try and pull out an office document Word thinks it's corrupt. Here's what I've tried so far (obviously the values have been changed to protect the innocent :): bcp "select document_binary_data from database where id = 12345" queryout "c:\filename.doc" -n -S server -U username -P password This isn't working though? Any thoughts?

    Read the article

  • How much Stored Procedures created everyday ?

    - by Space Cracker
    I make a query that return to me the count of Stored Procedure that created everyday as follow SELECT convert(varchar, crdate, 103) as Date,Count(*) as Counter FROM sysobjects WHERE (xtype = 'p') AND (name NOT LIKE 'dt%') Group by convert(varchar, crdate, 103) and its already work but dates appear in string format that i can't order it such as below 01/03/2010 3 01/04/2008 4 01/05/2010 5 01/11/2008 1 01/12/2008 4 02/03/2008 1 02/03/2010 2 02/04/2008 4 02/05/2010 2 02/11/2008 2 02/11/2009 2 02/12/2008 4 03/01/2010 1 03/02/2010 2 03/03/2010 2 03/04/2008 2 03/04/2010 2 03/05/2008 1 03/05/2010 2 I want to make that in which date is in datetime format that i can make order by successfully, i tried convert(datetime, crdate, 103) but it show Full date any idea of how to do ?

    Read the article

  • if else within CTE ?

    - by stackoverflowuser
    I want to execute select statement within CTE based on a codition. something like below ;with CTE_AorB ( if(condition) select * from table_A else select * from table_B ), CTE_C as ( select * from CTE_AorB // processing is removed ) But i get error on this. Is it possible to have if else within CTEs? If not is there a work around Or a better approach. Thanks.

    Read the article

< Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >