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 Articlet-sql where statement
In t-sql 2008 r2, I am trying to determine how to setup the sql to accomplish the following goal:select table1.customer_id,type,start_date,end_date,Program_id from table1 join table2 on...
View Articlereliability of using global temp table in shared stored procedures
Hello - In our reporting environment we have some reports that require the same basic information as a starting point so we have shared stored procedures that fulfill this need. For the case in...
View ArticleHow do you test a varchar column value to check for a coma
Could someone please help. I am trying to come up with a way to test a varchar(40) type column for a ',' coma in it's value. What I would like to do is inclose the string in double quotes if it...
View ArticleTransact SQL Query
Hi,We are using sql server 2012. This query is used by financial applications. Each client has multiple accounts. There will be multiple transactions happening on each account (like deposit,...
View ArticleHelp Please -Running Totals Trying to use Partition By
I have tried this but get a syntax error near 'ROWS' -for the life of me I cannot figure it out. Basically what I need is a running total of the rtv_qty by model_id and cust_id in date order. Any...
View Articleselect column by comparing data from another column
I have a table of products by their price.ProductPricebag1000gloves 200socks 400hat100need to select all products where price is greater than price of "gloves"...Dhananjay Rele
View ArticleAdvice on Large Inserts Please
I have searched through this Forum and gained lots of ideas but would like an overview of the options that I should consider.I need to import millions of rows from one database table (a couple of them...
View ArticleCode to find if a holiday falls on or between two dates
I have a table 'OrderMast' in which two of the columns are date/time; StartDate and EndDate.I am tasked to create a view 'vOrderMast' to include the StartDate and EndDate fields, and next to them an...
View ArticleDate difference function that returns minutes between two dates and excludes...
Is there a way to get this to work as a function? Currently returns error "Select statements included within a function cannot return data to a client"CREATE FUNCTION [dbo].[WorkDays](@DateFrom...
View ArticleUpdating SQL Server within a Fetch loop
The application provides sales personnel with the ability to create and save shopping carts for their customer accounts, until such time the customer is ready to place the order. The unit price of the...
View Articlei am getting error as An explicit value for the identity column in table...
--First tablecreate table product([id] int identity primary key,[name] nvarchar(50),[description] nvarchar(50)) insert into product values(1,'tv','52 inches '),(2,'laptops','16 inches...
View ArticleRecord Locking Question
Hello -I have inherited an old VB6 app with a Sql Server 2000 back end. The previous developer put in record-locking code in the VB app and created his/her own record-locking table. This does not...
View Articlexml path help required
I have query - I'm sorry, i have not specified exact tables / field names. I just want to how do I get my required out put.select empid, ename, cast ('<eventdata>' + '<dataitem>' +...
View ArticleCheck if table exists in default schema for a user?
In SQL server, how do I check if a table exists in the default schema for a particular user ?
View ArticleFind Related Items Help
I have two tables: (condensed version of Subject) Subject and MessageSubjectCREATE TABLE [dbo].[Subject]( [SubjectID] [int] IDENTITY(1,1) NOT NULL, [Name] [nchar](80) NULL, [Active] [bit] NULL ) ON...
View ArticleQuerying for existing set of values
HI,I have the following scenario. I have one table which has the measure_id,measure_value and date.For every date, I will be populating the measure_value for every measure_id. If the source, doesnt...
View ArticleConversion failed when converting date and/or time from character string
create table employee1 (id int,name varchar(10),datebirth date,gender varchar(10),deptid int)insert into employee values (1,'jitendra','2000-12-08','male',10) ,(2,'sabari','2002-12-08','male',11),...
View ArticleAn explicit value for the identity column in table 'productsales' can only be...
--first table create table product([id] int identity(1,1) primary key,[name] nvarchar(50),[description] nvarchar(50)) insert into product values('tv','52 inches '),('laptops','16 inches...
View ArticleTrying to Improve a Very Slow UPDATE
I am attempting to run an update that involves the following two tables. The indexes are listed below the table names, followed by the current number of records in the tables. The query contains come...
View Article