Search Results

Search found 1214 results on 49 pages for 'tomaz tsql'.

Page 14/49 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • Custom aggregation in GROUP BY clause

    - by Rire1979
    If I have a table with a schema like this table(Category, SubCategory1, SubCategory2, Status) I would like to group by Category, SubCategory1 and aggregate the Status such that if not all Status values over the group have a certain value Status will be 0 otherwise 1. So my result set will look like (Category, SubCategory1, Status) I don't want to write a function. I would like to do it inside the query.

    Read the article

  • Eclipse Debug Mode disrupting SQL Server 2005 Stored Procedure access

    - by Sathish
    We have a strange problem in our team. When a developer is using Eclipse in Debug mode, SQL Server 2005 blocks other developers from accessing a stored procedure. Debug session typically involves opening Hibernate session to persist an entity which could be accessing a stored procedure used for Primary key generation. Debugging is done in business logic code and rarely in JDBC stored procedure call. Is there any way to configure SQL server or the stored procedure so that other developers are not blocked?

    Read the article

  • basic sql group by with percentage

    - by David in Dakota
    I have an issue and NO it is not homework, it's just a programmer who has been away from SQL for a long time having to solve a problem. I have the following table: create table students( studentid int identity(1,1), [name] varchar(200), [group] varchar(10), grade numeric(9,2) ) go The group is something arbitrary, assume it's the following "Group A", "Group B"... and so on. The grade is on a scale of 0 - 100. If there are 5 students in each group with grades randomly assigned, what is the best approach to getting the top 3 students (the top 80%) based on their grade? To be more concrete if I had the following: Ronald, Group A, 84.5 George H, Group A, 82.3 Bill, Group A, 92.0 George W, Group A, 45.5 Barack, Group A, 85.0 I'd get back Ronald, Bill, and Barack. I'd also need to do this over other groups.

    Read the article

  • Trigger Code on a table in my ERP Database

    - by David Stein
    My ERP Vendor has the following trigger on a table: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER [dbo].[SOItem_DeleteCheck] ON [dbo].[soitem] FOR DELETE AS BEGIN DECLARE @RecCnt int, @LogInfo varchar(256) SET @RecCnt = (SELECT COUNT(*) FROM deleted) IF @RecCnt > 150 BEGIN RAISERROR (54010, 18, 1, 'SOItem') WITH LOG ROLLBACK TRANSACTION END SET @LogInfo = 'Deleting ' + LTRIM(STR(@RecCnt)) + ' Rows From SOItem' EXEC LogDeletes @LogInfo END GO This seems very inefficient to me. Doesn't select count(*) take longer than Count(specific field)?

    Read the article

  • SQL Server 2005/2008: Identify current user

    - by Torben H.
    Hello I have a web application, which is using a SQL Server 2005 database. My problem is, that the application has no role management. So the application always accesses the database with one default user. But now I have to save and access a value only for the current user. Is there any way to do this? Maybe something like a session on the web server? The best way would be, if there is any possibility to access the current session id of the web server from T-SQL. Do anyone understand my problem? :) Torben

    Read the article

  • view to select specific period or latest when null

    - by edosoft
    Hi I have a product table which simplifies to this: create table product(id int primary key identity, productid int, year int, quarter int, price money) and some sample data: insert into product select 11, 2010, 1, 1.11 insert into product select 11, 2010, 2, 2.11 insert into product select 11, 2010, 3, 3.11 insert into product select 12, 2010, 1, 1.12 insert into product select 12, 2010, 2, 2.12 insert into product select 13, 2010, 1, 1.13 Prices are can be changed each quarter, but not all products get a new price each quarter. Now I could duplicate the data each quarter, keeping the price the same, but I'd rather use a view. How can I create a view that can be used to return prices for (for example) quarter 2? I've written this to return the current (=latest) price: CREATE VIEW vwCurrentPrices AS SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY productid ORDER BY year DESC, quarter DESC) AS Ranking FROM product ) p WHERE p.Ranking = 1 I'd like to create a view so I can use queries like select * from vwProduct where quarter = 2

    Read the article

  • Will this force a reinitialize in Merge Replication Topology?

    - by Refracted Paladin
    I need to add a couple of columns to a table that is a part of a replication set. It is not a constraint coulumn or a part of any article filters and it allows NULL. I have a pretty good idea that I can run this -- ALTER TABLE tblPlanDomain ADD ReportWageES VARCHAR (100) NULL and NOT force all my clients to reinitialize but I was hoping for some reassurance. Can anyone verify this one way or the other for me? Thanks,

    Read the article

  • how to select the min value using having key word

    - by LOVE_KING
    I have created the table stu_dep_det CREATE TABLE `stu_dept_cs` ( `s_d_id` int(10) unsigned NOT NULL auto_increment, `stu_name` varchar(15) , `gender` varchar(15) , `address` varchar(15),`reg_no` int(10) , `ex_no` varchar(10) , `mark1` varchar(10) , `mark2` varchar(15) , `mark3` varchar(15) , `total` varchar(15) , `avg` double(2,0), PRIMARY KEY (`s_d_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=8 ; then Inserted the values INSERT INTO `stu_dept_cs` (`s_d_id`, `stu_name`, `gender`, `address`, `reg_no`, `ex_no`, `mark1`, `mark2`, `mark3`, `total`, `avg`) VALUES (1, 'alex', 'm', 'chennai', 5001, 's1', '70', '90', '95', '255', 85), (2, 'peter', 'm', 'chennai', 5002, 's1', '80', '70', '90', '240', 80), (6, 'parv', 'f', 'mumbai', 5003, 's1', '88', '60', '80', '228', 76), (7, 'basu', 'm', 'kolkatta', 5004, 's1', '85', '95', '56', '236', 79); I want to select the min(avg) using having keyword and I have used the following sql statement SELECT * FROM stu_dept_cs s having min(avg) Is it correct or not plz write the correct ans....

    Read the article

  • MDX performance vs. T-SQL

    - by SubPortal
    I have a database containing tables with more than 600 million records and a set of stored procedures that make complex search operations on the database. The performance of the stored procedures is so slow even with suitable indexes on the tables. The design of the database is a normal relational db design. I want to change the database design to be multidimensional and use the MDX queries instead of the traditional T-SQL queries but the question is: Is the MDX query better than the traditional T-SQL query with regard to performance? and if yes, to what extent will that improve the performance of the queries? Thanks for any help.

    Read the article

  • Microsoft T-SQL to Oracle PL/SQL translation

    - by Michael Prewecki
    I've worked with T-SQL for years but i've just moved to an organisation that is going to require writing some Oracle stuff, probably just simple CRUD operations at least until I find my feet. I'm not going to be migrating databases from one to the other simply interacting with existing Oracle databases from an Application Development perspective. Is there are tool or utility available to easily translate T-SQL into PL/SQL, a keyword mapper is the sort of thing I'm looking for. P.S. I'm too lazy to RTFM, besides it's not going to be a big part of my role so I just want something to get me up to speed a little faster.

    Read the article

  • Last byte missing when casting from varbinary to varchar

    - by xaxie
    I got the last byte losing when converting varbinary to varchar in some case. For example: DECLARE @binary varbinary(8000), @char varchar(8000) set @binary = 0x000082 set @char = CAST(@binary as varchar(8000)) select BinaryLength=DATALENGTH(@binary), CharLength=DATALENGTH(@char) The result is BinaryLength CharLength 3 2 The affected byte value is from 0x81 - 0xFE. The stranger thing is that if I use varchar(MAX) instead varchar(8000) when casting, there is no any problem. Could someone tell me the root cause of the issue? PS: I run the sql in MS SQL server 2008. Thanks!

    Read the article

  • Creating stored procedure having different WHERE clause on different search criteria without putting

    - by Muhammad Kashif Nadeem
    Is there any alternate way to create stored procedure without putting all query in one long string if criteria of WWHERE clause can be different. Suppose I have Orders table I want to create stored procedure on this table and there are three column on which I wnat to filter records. 1- CustomerId, 2- SupplierId, 3- ProductId. If user only give CustomerId in search criteria then query should be like following SELECT * FROM Orders WHERE Orders.CustomerId = @customerId And if user only give ProductId in search criteria then query should be like following SELECT * FROM Orders WHERE Orders.ProductId = @productId And if user only all three CustomerId, ProductId, and SupplierId is given then all three Ids will be used in WHERE to filter. There is also chance that user don't want to filter record then query should be like following SELCT * FROM Orders Whenever I have to create this kind of procedure I put all this in string and use IF conditions to check if arguments (@customeId or @supplierId etc) has values. I use following method to create procedure DECLARE @query VARCHAR(MAX) DECLARE @queryWhere VARCHAR(MAX) SET @query = @query + 'SELECT * FROM Orders ' IF (@originationNumber IS NOT NULL) BEGIN BEGIN SET @queryWhere =@queryWhere + ' Orders.CustomerId = ' + CONVERT(VARCHAR(100),@customerId) END END IF(@queryWhere <> '') BEGIN SET @query = @query+' WHERE ' + @queryWhere END EXEC (@query) Thanks.

    Read the article

  • Selecting a user-defined scalar function that takes as a parameter another field

    - by ghills
    I have a table a with a list of id's, and a user-defined function foo(id) that takes the id and returns a VARCHAR(20). What I am trying to do is: SELECT id, foo(id) AS 'text field' FROM a However, instead of calling the function for each ID number, like I desired, the text comes back the same for every row. I have tested the foo() function manually with the returned ID's and it does not have that problem, so I realize I must not understand something about the evaluation of the query.

    Read the article

  • recursive delete trigger and ON DELETE CASCADE contraints are not deleting everything

    - by bitbonk
    I have a very simple datamodel that represents a tree structure: The RootEntity is the root of such a tree, it can contain children of type ContainerEntity and of type AtomEntity. The type ContainerEntity again can contain children of type ContainerEntity and of type AtomEntity but can not contain children of type RootEntity. Children are referenced in a well known order. The DB model for this is below. My problem now is that when I delete a RootEntity I want all children to be deleted recursively. I have create foreign key with CASCADE DELETE and two delete triggers for this. But it is not deleting everything, it always leaves some items in the ContainerEntity, AtomEntity, ContainerEntity_Children and AtomEntity_Children tables. Seemling beginning with the recursionlevel of 3. CREATE TABLE RootEntity ( Id UNIQUEIDENTIFIER NOT NULL, Name VARCHAR(500) NOT NULL, CONSTRAINT PK_RootEntity PRIMARY KEY NONCLUSTERED (Id), ); CREATE TABLE ContainerEntity ( Id UNIQUEIDENTIFIER NOT NULL, Name VARCHAR(500) NOT NULL, CONSTRAINT PK_ContainerEntity PRIMARY KEY NONCLUSTERED (Id), ); CREATE TABLE AtomEntity ( Id UNIQUEIDENTIFIER NOT NULL, Name VARCHAR(500) NOT NULL, CONSTRAINT PK_AtomEntity PRIMARY KEY NONCLUSTERED (Id), ); CREATE TABLE RootEntity_Children ( ParentId UNIQUEIDENTIFIER NOT NULL, OrderIndex INT NOT NULL, ChildContainerEntityId UNIQUEIDENTIFIER NULL, ChildAtomEntityId UNIQUEIDENTIFIER NULL, ChildIsContainerEntity BIT NOT NULL, CONSTRAINT PK_RootEntity_Children PRIMARY KEY NONCLUSTERED (ParentId, OrderIndex), -- foreign key to parent RootEntity CONSTRAINT FK_RootEntiry_Children__RootEntity FOREIGN KEY (ParentId) REFERENCES RootEntity (Id) ON DELETE CASCADE, -- foreign key to referenced (child) ContainerEntity CONSTRAINT FK_RootEntiry_Children__ContainerEntity FOREIGN KEY (ChildContainerEntityId) REFERENCES ContainerEntity (Id) ON DELETE CASCADE, -- foreign key to referenced (child) AtomEntity CONSTRAINT FK_RootEntiry_Children__AtomEntity FOREIGN KEY (ChildAtomEntityId) REFERENCES AtomEntity (Id) ON DELETE CASCADE, ); CREATE TABLE ContainerEntity_Children ( ParentId UNIQUEIDENTIFIER NOT NULL, OrderIndex INT NOT NULL, ChildContainerEntityId UNIQUEIDENTIFIER NULL, ChildAtomEntityId UNIQUEIDENTIFIER NULL, ChildIsContainerEntity BIT NOT NULL, CONSTRAINT PK_ContainerEntity_Children PRIMARY KEY NONCLUSTERED (ParentId, OrderIndex), -- foreign key to parent ContainerEntity CONSTRAINT FK_ContainerEntity_Children__RootEntity FOREIGN KEY (ParentId) REFERENCES ContainerEntity (Id) ON DELETE CASCADE, -- foreign key to referenced (child) ContainerEntity CONSTRAINT FK_ContainerEntity_Children__ContainerEntity FOREIGN KEY (ChildContainerEntityId) REFERENCES ContainerEntity (Id) ON DELETE CASCADE, -- foreign key to referenced (child) AtomEntity CONSTRAINT FK_ContainerEntity_Children__AtomEntity FOREIGN KEY (ChildAtomEntityId) REFERENCES AtomEntity (Id) ON DELETE CASCADE, ); CREATE TRIGGER Delete_RootEntity_Children ON RootEntity_Children FOR DELETE AS DELETE FROM ContainerEntity WHERE Id IN (SELECT ChildContainerEntityId FROM deleted) DELETE FROM AtomEntity WHERE Id IN (SELECT ChildAtomEntityId FROM deleted) GO CREATE TRIGGER Delete_ContainerEntiy_Children ON ContainerEntity_Children FOR DELETE AS DELETE FROM ContainerEntity WHERE Id IN (SELECT ChildContainerEntityId FROM deleted) DELETE FROM AtomEntity WHERE Id IN (SELECT ChildAtomEntityId FROM deleted) GO

    Read the article

  • openquery issue in SQL Server

    - by George2
    Hello everyone, I am using SQL Server 2008 (let us call this source database server in this question discussion), and in SSMS, I have created a linked server to another SQL Server 2008 database (let us call this destination database server in this question discussion). When I issue statement -- select * from [linked server name].[database name].[dbo].[table name], error will be returned, Linked server "ZS" The OLE DB access interface "SQLNCLI10" returned "NON-CLUSTERED and NOT INTEGRATED "Index" ix_foo_basic_info_nf ", which is incorrect bookmark ordinal 0. When I issue statement -- select * from openquery([linked server name],'select * from [table name]'), there will be no errors, any ideas what is wrong? thanks in advance, George

    Read the article

  • Why is using OPENQUERY on a local server bad?

    - by Ziplin
    I'm writing a script that is supposed to run around a bunch of servers and select a bunch of data out of them, including the local server. The SQL needed to SELECT the data I need is pretty complicated, so I'm writing sort of an ad-hoc view, and using an OPENQUERY statement to get the data, so ultimately I end up looping over a statement like this: exec('INSERT INTO tabl SELECT * FROM OPENQUERY(@Server, @AdHocView)') However, I've heard that using OPENQUERY on the local server is frowned upon. Could someone elaborate as to why?

    Read the article

  • How to check for mutual existence of Fields in same table in Two columns

    - by ranabra
    I tried using "Exist" and "IN". Not only did I not succeed, it didn't seem as an efficient solution. Here is a simplified example: TblMyTable WorkerUserName  -  WorkerDegree  -  ManagerUserName  -  ManagerDegree I need a query where there is a mutual connection / existence. What I mean is only where the worker, ex. "John" has a manager named "Mary", and where Mary the manager has a worker named "John". John the worker can have several managers and Mary the manager can have several workers. So the result will be (the order doesn't matter) ideally in one line: John - BSc  --  Mary - M.A. or Mary - M.A.  --  John - BSc The punchline is it's only one table. it is not really managers and workers, this is just a simplification of the situation. In the real situation both are equal, in a Table of names of users working with other users. Database is SQL 2005. Many thanx in advance  

    Read the article

  • T-Sql Modify Insert SProc To Update If Exists.

    - by Goober
    Scenario I have a stored procedure written in T-Sql that I use to insert data into a table as XML. Since the data gets updated regularly, I want the rows to be updated if they already exist (Aside from when the application is first run, they will always exist). Question Below is the code of my Insert Sproc, however I cannot seem to workout the Update side of the stored procedure & would appreciate some help. CODE set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[INS_Curve] ( @Curve varchar(MAX) ) AS DECLARE @handle int exec sp_xml_preparedocument @handle OUTPUT, @Curve INSERT INTO CurveDB..tblCurve(LoadID,BusinessDate, Factor) SELECT LoadID,BusinessDate, Factor FROM OPENXML(@handle, 'NewDataSet/Table1',2) WITH( LoadID int, BusinessDate DateTime, Factor float ) exec sp_xml_removedocument @handle

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >