Complex Foreign Key to cover integrity check over graph of tables
I have the following tables structure:Site: ========== Id (PK) Name Location: ========== Id (PK, UQ1) SiteId (UQ1) Name Order: ========== Id (PK) SiteIdOrderLine: ========== Id (PK) OrderId...
View ArticleCount over table
This is my table schema CREATE TABLE submittedProblem ( userID int, contestID int, problemID int, score int ); INSERT INTO submittedProblem (userID, contestID, problemID, score) VALUES (1, 1, 1, 10),...
View ArticleTrouble casting a string as a float value and storing in a new variable
When I try to create my stored procedure, I get an error saying there is a problem, which I've narrowed down to the part where I try to set the value of a float variable based on the value of a...
View ArticleHow to detrimine date duration, minus weekend days and days on hold
I need to determine duration of a request by when the request went from Milestone_ 3 to Milestone_8 (but if Milestone_8 is null use Milestone_7) minus weekend minutes.But I also need to find the days...
View ArticleSchedule Agent Job as per calendar
Hi All,I have a requiremnt which needs to be automated using Sql Server Agent Job..I am not sure how it can be done.. I have a calendar table which consists 5yrs of dates column.. I need to schedule a...
View ArticleAFTER INSERT and AFTER UPDATE triggers on same table
Hello,I have a table "T" and 2 triggers on that table: TR1 and TR2. TR1 is an after insert trigger and TR2 is an after update trigger. The problem is that when TR1 executes an update on column "x" of...
View ArticleOrder By with Concatination
I am concatinating two columns together, ID and Name. But I want it to order by the name which is 9 characters over. I can't seem to find the right syntax. Can anyone tell me what is wrong? I have...
View ArticleObjects that goes to primary filegroup
Hello everybody, I have one database, that have around 2k tables and indexed views. teorically data on most of them should go to separated filegroups we have on different hard disk, and none of them...
View ArticleGet average number of duplicate records per user?
I am currently going through the activity log tables in the database to try and find out how many users make use of the application's batch processing functionality. As part of that, I'm trying to...
View ArticleHow much do CAST statements affect performance?
I have an 800+ line SELECT that I am tuning before using it as the source in an SSIS package. I have reduced the original time it took from around 19 minutes down to just under 2 minutes and now I'm...
View ArticleConversion failed when converting the varchar value '5,6' to data type int.
Hi,I am running the query below and it is throwing the following error: "Conversion failed when converting the varchar value '5,6' to data type int." I am thinking it has something to do with the IN...
View ArticleCalcuate Hours: Minutes:Seconds between two dates excluding Weekends
Hello All,@StartDate = '2014-06-21 13:37:30:037'@EndDate = GetDate()I want to find out Hours:Minutes:Seconds between the above dates EXCLUDING WEEKENDS.Please help.ReportingServices
View ArticleComputed column 'the_column' in table 'the_table' cannot be persisted because...
I am getting the following error when trying to create a table with computed column that points to a function:Computed column 'JobNumber' in table 'SB_B_JobT' cannot be persisted because the column is...
View Articlebuilding SCD2 table issue
Hello,I have to build SCD type 2 on one column value. Before I implement "catch-modification" in our DWH, I have to load historical data to such dimension.I have original table which is catching...
View Articlehow to concat multiple rows with same id in sql
how to concat multiple rows with same id in sql
View ArticleRolling Calculation
I'm using SQL Server 2012. I need to calculate the values for the result column in the table below:The result of the 1st row is already known. The result of the next row is (result of previous...
View Articlehow to show parentid only in front of first child
Hi, following query is from msdnhttp://technet.microsoft.com/en-us/library/ms190766(v=sql.90).aspxUSE AdventureWorks; GO WITH Sales_CTE (SalesPersonID, NumberOfOrders, MaxDate) AS ( SELECT...
View Articlesql join
HI,How to join these two statement on TripId. you don't need to understand the query .statement 1----------------------------------------------SELECT tblTrips.TripId,tblTrips.DestinationDistrictId,...
View ArticleFormatting SQL table data by creating a new column
Hi All,I am not able to figure it out how I can solve issue by writing sql query.In below screen shot yellow columns are the source and green colour are output columns. How can I write a sql query to...
View ArticleCan balance tree go un balance in following condition. ( b-tree of primarykey)
Hi, Please tel me how b-tree of clustered index will look like if i have 1,2,3,4 then there is gap 6,7,8,9 then gain there is gap 40 ,41,42,then it goes continuasly to 300. Q1) I want to ask the...
View Article