How to retrieve the min(StartDate) and Max(EndDate) from each group in one...
I have two groups in the following dataset -- group 'a' and group 'b'. Is there a Tsql query to retrieve the Min(sDate) and Max(eDate) for each group in one row per group? If there is a way to...
View ArticleConvert Access Module to SQL Function - Hex To Dec conversion
I need to convert an Access Module to a SQL Function but not sure how to successfully accomplish this.The module has several different functions to convert hexadecimal numbers to decimal and vice...
View Articletuning up indexes
Environment: SQL Server 2008R2 Problem: the total cost value of the CPU for running basic Select statement is 99%. When integrating Select statement with left outer join, it slows down the performance...
View ArticleUpdate with Count Distinct?
Hi,I have the following table (an example): CREATE TABLE mytable( mukey nvarchar (30) NULL, cokey nvarchar (30) NULL, ncomp int NULL); INSERT INTO mytable(mukey, cokey, ncomp) VALUES ('1017271',...
View ArticleUnique constraint SQL condition
I wanted to create conditional unique constraint that column combination will be unique if value is not 0 e.g. columnA columnB 1 1 1 2 1 3 1 0 1 0 2 1 2 2 2 3 this will not raise error on first...
View ArticleExtracting string value within set of parameters in a column
I have a question. I need a query which only return the value inside a particular range within a field in a column.In the below example, I am trying to create a fourth column which returns only data...
View ArticlePls. Hepl! TSQL Filter Technique
Hi Experts,Some sort of help about filter that adds different columns, see statementSelect Account, Reference, lastname + ', ' + firstname + ' ' + middlename as Fullname /*Is it possible from the where...
View ArticleDynamic column and dynamic row amount summation
i want one more Column and Row for Sum of Amount CREATE TABLE #Table2 (Project VARCHAR(50),Ledger VARCHAR(100),Amount DECIMAL(18,3)) INSERT INTO #Table2 values ('Project1','Ledger1',1000.00) INSERT...
View ArticleHow to merge two SQL rows (same item ID) with the SUM() qty but show only the...
I was trying to use DISTINCT to show unique record, but not every column has same value.Is there a way to merge my Count column's value of two rows that have the same UPC (item ID) but only show the...
View ArticleHow SQL Indexing Works
SQL server store the data on HardDisk. If we query the data it load the data from HardDisk into memory. What will happen if we index the table. Where the indexing really happens , is it performed on...
View ArticleIDENTITY BIG JUMP (1000/10000) a Feature?
I thought it was a bug.QUOTE: "Microsoft declares it is a feature rather than a bug and in many scenarios it would be helpful. But in our case, it would not be acceptable because that number is shown...
View ArticleTransaction isolation concurrency violation
Problem:It seems that records which are inserted within a transaction Tx1 (Isolation=read committed) can be read by another transaction Tx2 (Isolation=read committed) during running transaction...
View ArticleDeadLock on Same Wait resource
<deadlock><victim-list><victimProcess id="process10258508" /></victim-list><process-list><process id="process10258508" taskpriority="0" logused="912"...
View ArticleHelp concatenating data
Help concatenating a fieldI need to create a query that concatenates potentially several fields into one field. Below is the water_group table which contains the WaterGroupID and WaterID. There can be...
View ArticleSEQUENCE Object for Small Tables Only?
QUOTE from a recent thread: "Long term solution should be to use SEQUENCE with NO CACHE for small tables instead of identity and benefit from performance improvement for large tables."Thread:...
View ArticleLooping percentages
CREATE TABLE projecthours([Resource_id] [varchar](25) NOT NULL, [Project_Id] varchar null, [ResourceName] [varchar](101) NULL, [Calendar_month] [int] NULL, [Calendar_Year] [int] NULL, [Project Hours]...
View ArticleTSQL Help in finding dates overlapping
Hi i am working on insurance project, which deals with user policies.Following are sample user policy details, i want to find out user association in years with the companyUser can have number of...
View ArticleTable Data type having length 4 but its allowed more than 4
SQL Server 2008 r2 sp21 In database table 1 field width is showing 42 In a table for the same field some values is more than 4 digit3 I tried to...
View ArticleQuery with a WHILE loop
DECLARE@databasenameAS NVARCHAR(128);SET@databasename=(SELECT MIN(name)FROMsys.databasesWHEREnameNOT IN ('master','model', 'msdb','tempdb')); WHILE@databasenameIS NOTNULLBEGIN PRINT@databasename;...
View Article