Summing a field if another field = scrap
I'm working on a report where I need to sum a field if another field=scrap. I have tried to make it work a couple of other ways but have had no luck. Any suggestions would be appreciated, since I'm new...
View ArticleSelect table name dynamically
I want to create a cursor in which the select statement should be dynamic:<o:p></o:p>if @PhoneType = White<o:p></o:p>Then the select statement should be...
View ArticleSplit date range without Calendar table
Hi guys!Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?Reason I'm asking this is because we have a huge Fact...
View ArticleHow to add a text to an xml element
Hi Guys,i'm trying to export some course information from sql to xml using the explicit mode.my root element is <Courses> my subement is <Course>I would like to add the following code to my...
View ArticleSchema Bind View
What is schema bind view? Can anyone explain with suitable example ? When we need schema bind view how its helpful for performance
View ArticleRelationship between 2 tables question
Hello guys, I'm new to SQL and I'm wondering if the relationship I've done below is correct or what else could I change to make it better? Thanks in advance.CREATE TABLE Cinema ( CinemaID int NOT NULL...
View ArticleHow to Get Missing Dates for Each Support Ticket In My Query?
Hello - I'm really baffled as to how to get missing dates for each support ticket in my query. I did a search for this and found several CTE's however they only provide ways to find missing dates in a...
View ArticleAnother view is using the indexes applied on a different Indexed View
Hello, I have not played around much with Indexed views. We are building a SSRS report that has millions of rows.The report is almost complete now and trying to improve performance.There was an...
View ArticleIs there a custom function available which can be used for logging errors...
Is there a custom function available which can be used for logging errors captured in a sp during and after execution in a sql table?Basically we would like to utilize such function in every sp and...
View ArticleWierd insert error on Foreign key conflict
Dear allI have a weird issue while entering a data into one table which reference as a FK in an otherIf I enter manually the following in my PropertyType Table :INSERT INTO...
View Articlesp_who2 gives a suspended status without a blkby
What does it mean when my stored procedure on a session runs slow and i look at sp_who2 and it gives status suspended but with no blkby session... Why is the session getting suspended and how can i...
View ArticlePercentile excel formula in SQL
Hi Friends, I want to do percentile function of excel in sql but I'm unable to do it. Below link shows the working of percentile function in...
View ArticleSelect query to transform table
Hello, I don't know who to go about selecting rows from a purchase table and transform the result as shown on the attached picture. I don't even know if this is possible. My boss wants me to get a...
View ArticleSProc executing twice - or getting Msg 233, Level 20 transport-level error...
I am connected the local SQL Server. In a Query Window I try the following. At first It was executing the sproce twice. I closed the query window (several times) and reopened a new one. Stripped out...
View ArticleCreating index on view
i have a very complex view , which is running very very slow i need to create an index, how to do it and what is the syntex Regardsk
View ArticleFilter within a Description
SELECT [Branch], SUM(qty) as TotalQty FROM ( SELECT LEFT([Desc] + ' ',charindex(' ', [Desc], 1)) AS [Branch], [DESC], qtyFROM ARD1 WHERE DATE BETWEEN '2013-12-01' AND '2013-12-31' ) AS X GROUP BY...
View ArticleCalculate the week number in a FiscalYear that starts in July
I need to know the week number of certain dates within a fiscal year that always begins July 1 and ends June 30. I need this for a span time over more than one year. The data range will be from July...
View ArticleBCP - Import Date into field type of Date fails
I am using 2008 R2.I have text files with dates shown as 01/01/2014. When I use BCP to import the text into a datetime field it works. When I try to import it into a date field, it fails with...
View ArticleT-SQL execution command line utility
When attempting to run this installer (SQLCMD T-SQL execution command line utility), I get the DOS screen but not the 1> command prompt. If I leave the screen alone, the DOD command window closes...
View ArticleOmit specific string from a given string
Hi, I need to omit some specific stng in a given string, Here is an example. Declare @Original varchar(100) Declare @Omit Varchar(25) Set @Original = 'Globe is sphere, Box is Square, Ring is circle,...
View Article