Query using Union All and CTEs is slow
TypePatient [ednum] int NOT NULL, PK [BackgroundID] int NOT NULL, FK [Patient_No] varchar(50) NULL, FK [Last_Name] varchar(30) NULL, [First_Name] varchar(30) NULL, [ADateTime] datetime NULL, Treat...
View ArticleSql conversion to access
How would I be able to write this query out in access? SELECT New.BRAND, SUM(NEW.QTY)QTY FROM(SELECT LEFT([Desc], CHARINDEX(' ',[DESC], 1)) AS Brand, qty FROM ARD WHERE DATE BETWEEN '12/01/2013' AND...
View ArticleUpdate a field multiple times, but only if the field is empty
I am having trouble updating a field in my table based upon a set of 7 different rules. I have been scratching my head at this for a few days, and am not sure what exactly is wrong, but am sure there...
View ArticlePivot rows to columns dynamically
I want to convert row data into columnsdynamically.Reg no Title Marks 10900231 Asgn 1 10.00 10900231 Asgn 3 5.00 10900231...
View Articleadding one more table to query makes execution time 100 times greater
I've got a view that's based on a query that uses 5 tables from one database and 1 table from another database. It has worked fine in production for several years.The SQL statement includes a CASE...
View ArticleCalculate cross duration for date times
Hello,I have a table "experience" which contains start and end data for each experience for each job seekers.I need to know the total cross duration of experience for any job seekers.For example, check...
View ArticlePermutations (difficult one)
Hi, We're tyring to find the best way to solve the following, hope you can help please. We have a fairly large table of users (2500+) and the users belong to 1 or more groups (at the moment the max...
View ArticleHow to backup data in table?
hi friends,How do I backup 1500 rows of data in products table in a databaseDB1? (the last column is varbinary type for images)How do I insert backed up 1500 rows of data in to the products table (this...
View ArticleRange date SQL 2008. If a record is set in the same time in two different rows
Hi guys a quick question: having a date (nvarchar format) like this 2013-02-22 00:00:00.0000000 how can I transform in date? And most important, having a structure likeidRec idContract From To 1 11...
View Articleerror 'DAYOFWEEK' is not a recognized built-in function name.
hi friend I used the following query with sql server 2008 to select group by recordsSELECT sum(ljoin)as lct, sum(rjoin)as rct, CONCAT(DATE_FORMAT(DATE_ADD(date, INTERVAL(1-DAYOFWEEK(date))...
View ArticleSelect column by ordinal position
Is there any way to select columns by ordinal position rather than by name?Something likeSelect t.[1] as col1, t.[2] as col2FROM table tThe question comes because of a very specific situation where...
View ArticleINSERT INTO MSAccess Linked Table Memo Field FROM SQL Server VARCHAR Field
I know I am doing the opposite of everyone else. But I need to INSERT INTO MSAccess Linked Table Memo Field FROM SQL Server VARCHAR Field. Don't ask why...I have tried CAST and it does not seem to...
View Article30 M rows in SQL Server 2008 R2- View or Table for faster performance
Hello,I am creating a SSRS 2008 report that currently is using a view. It's a view made out of one table and is not indexed.There are 70 some columns that I am displaying in the report with 10 or so...
View ArticleRAISERROR won't compile in sproc
I have an stored proc with code that looks like:BeginBegin tryBegin TranCommitEnd tryBegin Catch-- get the error values and write them to a log table by executing another stored procROLLBACK-- here is...
View ArticleCan we populate time dimension table in a specific order?
I am trying to load time dimension in a specific order and have attached (below) having sample data showing actual and desired outputdesired output BIZ_YEAR BIZ_MONTH BIZ_MONTH_VAL 2000 1 Jan 2000 2...
View ArticleUpdate Trigger Assistance - Update Same Row More than Once?
Good morning,I'm new to Triggers and am not understanding why this is not working. I've tried the web and none of the articles seem to answer my question. What I'm trying to do is clean a string and...
View ArticleUpdating records using self join or row number function
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp GO CREATE TABLE #Temp ( ID INT , CYear INT , Val INT , Descrp Varchar(10) NULL , Cd INT , ToBeUpdated Varchar(5) NULL ) INSERT INTO #Temp ( ID...
View ArticleNeed help in SQL Query
Hi - I have below two tables:Table1:store date revenue A 10-01-2013 10 A 11-01-2013 100 A 12-01-2013 12 B 10-01-2013 33 B 11-01-2013 56 B 12-01-2013 56Table2:Store month year Status A 10 2013 Managed A...
View ArticleUnfamiliar SELECT Statement
Hello, all -I'm reverse-engineering a stored procedure to clean it up, de-pasta-ize it and then excise as much as possible from the sp to use in an SSIS procedure.While going over the sp, I've come...
View ArticlePATINDEX problem
I'm using PATINDEX combined with SUBSTRING to strip off leading zeros or letters. I can strip off either a zero or a letter but not both. For example:'P102' should return '102''P0102' should return...
View Article