Tag: tsql

SQL Server 2008 ssrs multiple records into one

I’ve been reading other similar “multiple records into one” posts, but either cannot seem to get any to work, or they don’t really apply to what I am trying to do. Here are my 3 tables. vehicle, vehicle_repair, comments vehicle columns: vehicle_name and other vehicle related info,vehicle_make, vehicle_model vehicle_repair columns: vehicle_name, vehicle_repair_type, vehicle_repair_num, etc, etc […]

Choosing and assigning a value based among the duplicate records in sql

My data looks as below: Student_ID State 1 WI 1 IL 1 IL 2 WI 3 IL 4 IL 4 MN I want my Output to be as follows: Ouput: If the same student is in both WI and any other state then we need to mention as ‘multiple’, when student is only in WI […]

Some tables id column do not auto increment despite being identity

I am troubleshooting a db (not my forte) that has some tables that are auto incrementing on the id column and some tables are not? Now all the tables are set as identity and marked to disallow null. I am using SSMS what else can I check or do to get these tables back to […]

calculation of amount for quarter

I have a question, I want merge my table data through date, All information provide in given table If Aggregation =Quaterly My table Table-1 Amount | Date | Aggregation 100 | 2013-01-01 | Quaterly 100 | 2013-02-01 | Quaterly 100 | 2013-03-01 | Quaterly 200 | 2013-04-01 | Quaterly 200 | 2013-05-01 | Quaterly 200 […]

TSQL Aggregate function in update statement

This is my query UPDATE [P1_Log_FY14H1_CE] SET [P1_Log_FY14H1_CE].toplevelAccredCode = #PartnerLookupfinalForCode.Accreditation_Code FROM dbo.[P1_Log_FY14H1_CE] INNER JOIN #PartnerLookupfinalForCode ON [P1_Log_FY14H1_CE].[Partner ID] = #PartnerLookupfinalforCode.Partner_ID WHERE [P1_Log_FY14H1_CE].Intake_Date is not null and #PartnerLookupfinalforCode.[Rank]=(Select Min(Rank) from #PartnerLookupfinalforCode) Here When updateing Toplevelaccredcode I m getting results like this [Partner ID] Code Rank A silver 3 A LessSilver 4 Here In log table partner […]

CAST to int used with LEFT on an nvarchar field not working properly?

I’m trying to create a view where I union 4 tables. One of the fields is a document number. The only way I can pull the related document number from one of the tables is by running a LEFT on the 6 left-most characters. But when I do this and then CAST to integer I […]

T-SQL – Updating value that isn't changing, is work performed?

This is my first question on here, so please go easy on me :)….I tried searching on the web, as well as other answered questions on here, but I couldn’t think of a good way to word this short enough for Google to pick up any good matches. This seems like a T-SQL 101 question […]

T-SQL Insert – Select in Table variable is very slow

I have a table variable and I am inserting in it some values using the “Insert Into – Select” statement. The select is a combination of few joins, and when it is executed separately it takes 3 seconds. The problem is that the whole code takes 3-4 minutes to executed. I wonder is there a […]

Create different filegroup for different Schema

I need to create a filegroup for schema I have in SQL Server. The DB is empty and I just want to create schema and their filegroups. How can I do that?

Recursive function improperly breaking up badly maintained CSV string field

Here is a setup to demonstrate the problem: create table foo ( [goat] [varchar](20) NOT NULL, [email] [varchar](max) NULL, [id] [int] NOT NULL ) GO INSERT INTO foo ( [goat], [email], [id] ) values (‘bluegoat’, ‘hello@goat.com’, 1), (‘bluegoat_addl_emails’, ‘goats@goat.com,cow@goat.com,wolf@goat.com,dog@goat.com,kitten4235@goat.com’,1) GO select * from foo GO –to test the setup, it should look like this: goat […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.