Search Results

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

Page 59/1156 | < Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >

  • SQL Server - CAST AND DIVIDE

    - by rs
    DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION ALL SELECT '3.123', 2 UNION ALL SELECT '7.0', 3 UNION ALL SELECT '80000', 4 UNION ALL SELECT NULL, 5 SELECT CASE WHEN PATINDEX('^[0-9]{1,5}[\.][0-9]{1,3}$', XYZ) = 0 THEN XYZ WHEN PATINDEX('^[0-9]{1,8}$',XYZ) = 0 THEN CAST(XYZ AS decimal(18,3))/1000 ELSE NULL END FROM @table This part - CAST(XYZ AS decimal(18,3))/1000 doesn't divide value it gives me more number of zeros after decimal instead of dividing it. (I even enclosed that in brackets and tried but same result) Am i doing something wrong here?

    Read the article

  • Displaying tree path of record in SQL Server 2005

    - by jskiles1
    An example of my tree table is: ([id] is an identity) [id], [parent_id], [path] 1, NULL, 1 2, 1, 1-2 3, 1, 1-3 4, 3, 1-3-4 My goal is to query quickly for multiple rows of this table and view the full path of the node from its root, through its superiors, down to itself. The ultimate question is, should I generate this path on inserts and maintain it in its own column or generate this path on query to save disk space? I guess it depends if this table is write heavy or read heavy. I've been contemplating several approaches to using the "path" characteristic of this parent/child relationship and I just can't seem to settle on one. This "path" is simply for display purposes and serves absolutely no purpose other than that. Here is what I have done to implement this "path." AFTER INSERT TRIGGER - requires passing a NULL path to the insert and updating the path for the record at the inserted rows identity INSTEAD OF INSERT TRIGGER - does not require insert to have NULL path passed, but does require the trigger to insert with a NULL path and updating the path for the record at SCOPE_IDENTITY() STORED PROCEDURE - requiring all inserts into this table to be done through the stored procedure implementing the trigger logic VIEW - requires building the path in the view 1 and 2 seem annoying if massive amounts of data are entered at once. 3 seems annoying because all inserts must go through the procedure in order to have a valid path populated. 1, 2, and 3 require maintaining a path column on the table. 4 removes all the limitations of the above but require the view to perform the path logic and requires use of the view if a path is to be displayed. I have successfully implemented all of the above approaches and I'm mainly looking for some advice. Am I way off the mark here or are any of the above acceptable? Each has it's advantages and disadvantages.

    Read the article

  • CTE and last known date processing

    - by stackoverflowuser
    Input @StartDate = '01/25/2010' @EndDate = '02/06/2010' I have 2 CTEs in a stored procedure as follows: with CTE_A as ( [gives output A..Shown below] ), with CTE_B as ( Here, I want to check if @StartDate is NOT in output A then replace it with the last known date. In this case, since @startdate is less than any date in output A hence @StartDate will become 02/01/2010. Also to check if @EndDate is NOT in output A then replace it with the last known date. In this case, since @enddate is 02/06/2010 hence it will be replace with 02/05/2010. // Here there is a query using @startDate and @EndDate. ) output A Name Date A 02/01/2010 B 02/01/2010 C 02/05/2010 D 02/10/2010

    Read the article

  • Design SQL Query for following case

    - by rs
    Consider tables Table1 id, name 1 xyz 2 abc 3 pqr Table2 id title 1 Mg1 2 Mg2 3 SG1 Table3 Tb1_id tb2_id count 1 1 3 1 2 3 1 3 4 2 2 1 3 2 2 3 3 2 I want to do query to give result like id title 1 MG1 2 MG2 3 Two or More Title MG1 has higher preference if MG1 and count = 1 then it is given as MG1 title , for others corresponding title is used and for count 1 as two or more

    Read the article

  • Strange Values in SYS.DM_TRAN_LOCKS table RESOURCE_ASSOCIATED_ENTITY_ID column

    - by AJM
    I’ve been trying to understand some strange values in the RESOURCE_ASSOCIATED_ENTITY_ID column of SYS.DM_TRAN_LOCKS when RESOURCE_TYPE is “OBJECT”. Although these should be object Ids, I cannot determine what object they actually refer to. I’ve tried everything I can think of, including querying all system tables with columns of type INT and BIGINT to see if I can find the value. No luck. The funny values actually appear in SYS.DM_TRAN_LOCKS, SYS.SYSLOCKINFO and SP_LOCK.

    Read the article

  • Help with a t-sql query

    - by user324650
    Hi Based on the following table Path ---------------------- area1 area1\area2 area1\area2\area3 area1\area2\area3\area4 area1\area2\area5 area1\area2\area6 area1\area7 Input to my stored procedure is areapath and no.of children (indicates the depth that needs to considered from the input areapath) areapath=area1 children=2 Above should give Path ----------- area1 area1\area2 area1\area2\area3 area1\area2\area5 area1\area2\area6 area1\area7 similary for areapath=area2 and children=1 output should be Path --------------- area1\area2 area1\area2\area3 area1\area2\area5 area1\area2\area6 I am confused how to write a query for this one.

    Read the article

  • exact full text search - sql server 2005

    - by csetzkorn
    Hi, Is it possible to do an 'exact full text search' with CONTAINS. I have removed all noise words etc. but the dbms still seems to manipulate the 'exact word' (e.g. 'j-blade - blade'). Can I disable this? Thanks. Christian PS: I would like to avoid like because it is too slow and with exact I mean that the text contains the exact word.

    Read the article

  • Entity Framework How to specify paramter type in generated SQL (SQLServer 2005) Nvarchar vs Varchar

    - by Gratzy
    In entity framework I have an Entity 'Client' that was generated from a database. There is a property called 'Account' it is defined in the storage model as: <Property Name="Account" Type="char" Nullable="false" MaxLength="6" /> And in the Conceptual Model as: <Property Name="Account" Type="String" Nullable="false" /> When select statements are generated using a variable for Account i.e. where m.Account == myAccount... Entity Framework generates a paramaterized query with a paramater of type NVarchar(6). The problem is that the column in the table is data type of char(6). When this is executed there is a large performance hit because of the data type difference. Account is an index on the table and instead of using the index I believe an Index scan is done. Anyone know how to force EF to not use Unicode for the paramater and use Varchar(6) instead?

    Read the article

  • SQL Server: "Mostly-unique" index

    - by Ian Boyd
    In a table i want to ensure that only unique vales exist over the five-column key: Timestamp Account RatingDate TripHistoryKey EventAction ========= ======= ========== ============== =========== 2010511 1234 2010511 1 INSERT 2010511 1234 2010511 4 INSERT 2010511 1234 2010511 7 INSERT 2010511 1234 2010511 1 INSERT <---duplicate But i only want the unique constraint to apply between rows when EventAction is INSERT: Timestamp Account RatingDate TripHistoryKey EventAction ========= ======= ========== ============== =========== 2010511 1234 2010511 1 INSERT 2010511 1234 2010511 1 UPDATE 2010511 1234 2010511 1 UPDATE <---not duplicate 2010511 1234 2010511 1 UPDATE <---not duplicate 2010511 1234 2010511 1 DELETE <---not duplicate 2010511 1234 2010511 1 DELETE <---not duplicate 2010511 1234 2010511 1 INSERT <---DUPLICATE Possible?

    Read the article

  • Contains performs MUCH slower with variable vs constant string MS SQL Server

    - by Greg R
    For some unknown reason I'm running into a problem when passing a variable to a full text search stored procedure performs many times slower than executing the same statement with a constant value. Any idea why and how can that be avoided? This executes very fast: SELECT * FROM table WHERE CONTAINS (comments, '123') This executes very slowly and times out: DECLARE @SearchTerm nvarchar(30) SET @SearchTerm = '123' SET @SearchTerm = '"' + @SearchTerm + '"' SELECT * FROM table WHERE CONTAINS (comments, @SearchTerm) Does this make any sense???

    Read the article

  • Need help with a SQL CTE Query

    - by Chuck
    I have a table that I need to get some specific data from for a view. Here's the base table structure with some sample data: | UserID | ReportsToUserID | Org ID | ------------------------------------- | 1 | NULL | 1 | ------------------------------------- | 2 | 1 | 1 | ------------------------------------- | 3 | 2 | 1 | ------------------------------------- | 4 | 3 | 1 | ------------------------------------- The users will be entering reports and users can see the reports of users who report to them and any users who report to those users. Users who report to no one can see everything in their organization Given my sample data above, user 1 can see the reports of 2, 3, & 4; user 2 can see the reports of 3 & 4; and user 3 can see the reports of 4. For the view, I'd like to have the data returned as follows: | UserID | CanSeeUserID | OrgID | -------------------------------------------- | 1 | 2 | 1 | -------------------------------------------- | 1 | 3 | 1 | -------------------------------------------- | 1 | 4 | 1 | -------------------------------------------- | 2 | 3 | 1 | -------------------------------------------- etc... Below is my current code, any help is greatly appreciated. WITH CTEUsers (UserID, CanSeeUserID, OrgID) AS ( SELECT e.ID, e.ReportsToUserID, e.OrgID FROM Users e WITH(NOLOCK) WHERE COALESCE(ReportsToUserID,0) = 0 --ReportsToUserID can be NULL or 0 UNION ALL SELECT e.ReportsToUserID, e.ID,e.OrgID FROM Users e WITH(NOLOCK) JOIN CTEUsers c ON e.ID = c.UserID ) SELECT * FROM CTEUsers

    Read the article

  • T-SQL QUERY PROBLEM

    - by Sam
    Hi All, I have table called Summary and the data in the table looks like this: ID Type Name Parent 1 Act Rent Null 2 Eng E21-01-Rent Rent 3 Prj P01-12-Rent E21-Rent 1 Act Fin Null 2 Eng E13-27-Fin Fin 3 Prj P56-35-Fin E13-Fin I am writing a SP which has to pull the parent based on type. Here always the type Act has ID 1, Eng has ID 2 and Prj has ID 3. The type ACT parent is always NUll, type Eng parent is Act and type Prj parent is Eng Now I have table called Detail.I am writing a SP to insert Detail Table data to the Summary table. I am passing the id as parameter: I am having problem with the parent. How do I get that? I can always say when ID is 1 then parent is Null but when ID is 2 then parent is name of ID 1 similarly when ID is 3 then parent is name of ID2. How do I get that? Can anyone help me with this:

    Read the article

  • Copy 2 databases without detach in SQL 2005

    - by molgan
    Hello I have a server with live databases, and I have a test-server where I sometimes restore databases from the live one, to get fresh data. But this way I have to set up all the users again, I have about 4 different users with different permissions that need set again. Is there some way to do this a better way without using detach and attach, since I cant take the databases offline on the live-server? Prefered some thing I could run that "re-fills" the tables with fresh data. No need to redo stored procedures and rights. /M

    Read the article

  • SQL Server 2005 Create Table with Column Default value range

    - by Matt
    Trying to finish up some homework and ran into a issue for creating tables. How do you declare a column default for a range of numbers. Its reads: "Column Building (default to 1 but can be 1-10)" I can't seem to find ...or know where to look for this information. CREATE TABLE tblDepartment ( Department_ID int NOT NULL IDENTITY, Department_Name varchar(255) NOT NULL, Division_Name varchar(255) NOT NULL, City varchar(255) default 'spokane' NOT NULL, Building int default 1 NOT NULL, Phone varchar(255) ) I tried Building int default 1 Between 1 AND 10 NOT NULL, that didn't work out I tried Building int default 1-10, the table was created but I don't think its correct.

    Read the article

  • MSSQL 2005 FOR XML

    - by Lima
    Hi, I am wanting to export data from a table to a specifically formated XML file. I am fairly new to XML files, so what I am after may be quite obvious but I just cant find what I am looking for on the net. The format of the XML results I need are: <data> <event start="May 28 2006 09:00:00 GMT" end="Jun 15 2006 09:00:00 GMT" isDuration="true" title="Writing Timeline documentation" image="http://simile.mit.edu/images/csail-logo.gif"> A few days to write some documentation </event> </data> My table structure is: name VARCHAR(50), description VARCHAR(255), startDate DATETIME, endDate DATETIME (I am not too interested in the XML fields image or isDuration at this point in time). I have tried: SELECT [name] ,[description] ,[startDate] ,[endTime] FROM [testing].[dbo].[time_timeline] FOR XML RAW('event'), ROOT('data'), type Which gives me: <data> <event name="Test1" description="Test 1 Description...." startDate="1900-01-01T00:00:00" endTime="1900-01-01T00:00:00" /> <event name="Test2" description="Test 2 Description...." startDate="1900-01-01T00:00:00" endTime="1900-01-01T00:00:00" /> </data> What I am missing, is the description needs to be outside of the event attributes, and there needs to be a tag. Is anyone able to point me in the correct direction, or point me to a tutorial or similar on how to accomplish this? Thanks, Matt

    Read the article

  • SQL SERVER Project

    - by Saif Omari
    My Application Database Without Project and without Source safe, i planned to make my DB to be as project and add it to TFS, but I have no idea how to script the stored procedures, Triggers, Views, Functions, and what is the best practice to Make Update Script for All My stored procedures, Triggers, Views, and Functions to My customers DB.

    Read the article

  • Help needed in AdventureWorks in a sql query.

    - by vaibhav
    I was just playing with adventureworks database in sqlserver. I got stuck in a query. I wanted to Select all titles from HumanResources.Employee which are either 'Male' or 'Female' but not both. i.e if title Accountant is Male and Female both I want to leave that title. I need only those titles where Gender is either Male or Female. I have done this till yet. select distinct(title) from humanresources.employee where gender='M' select distinct(title) from humanresources.employee where gender='F' Probably a join between these two queries, would work. But If you have any other solution, please let me know. It is not a homework. :) Thanks in advance.

    Read the article

  • Passing delimited string to stored procedure to search database

    - by rs
    How can i pass a string delimited by space or comma to stored procedure and filter result? I'm trying to do something like - Parameter Value -------------------------- @keywords key1 key2 key3 Then is stored procedure i want to first find all records with first or last name like key1 filter step 1 with first or last name like key2 filter step 2 with first or last name like key 3

    Read the article

  • SQL Temp Tables & Replication

    - by Refracted Paladin
    I have had an issue with our replication process and would like to salvage some data. I have a process in place where I will connect to each subscriber before flagging them for reinitialization and I will run the below to pull any data they may have entered in during the "dark time". I am pretty sure this will work in a vanilla palace. What I am unsure of is whether the Global Temporary Table will persist through DB Replication. To be clear, I am not trying to Replicate the TempTable, I just want to make sure it will still exist at the local DB after the Replication so I may run the INSERT from it. Thoughts? USE MemberCenteredPlan -- Select Data from tblPLan SELECT * INTO ##MyPlan FROM tblPlan WHERE PlanID = 407869 --------------------------- -- Run Replication Process --------------------------- -- Insert Plan back into DB INSERT INTO tblPlan SELECT * FROM ##MyPlan WHERE PlanID = 407869 -- Drop Global Temp Table DROP TABLE ##MyPlan --------------------------- -- Run Replication Process ---------------------------

    Read the article

  • Improve SQL Server 2005 Query Performance

    - by user366810
    I have a course search engine and when I try to do a search, it takes too long to show search results. You can try to do a search here http://76.12.87.164/cpd/testperformance.cfm At that page you can also see the database tables and indexes, if any. I'm not using Stored Procedures - the queries are inline using Coldfusion. I think I need to create some indexes but I'm not sure what kind (clustered, non-clustered) and on what columns. Thanks

    Read the article

< Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >