Redirect SQL Server Instance to a new instance?

I have a web application that connects to a SQL Server named instance as OLDSERVER\OLDINSTANCE. I need to redirect the traffic to NEWSERVER\NEWINSTANCE. I know you can redirect SQL Server database connections using the SQL Server Client Network Utility (cliconfig.exe) with an alias, but it doesn’t seem to support aliasing connections with instances. Does anyone […]

Entity Framework updates local database, but update script gives an error when applied to production

I have a local dev environment and database that I update automatically with Update-Database, and then apply the migrations to the production environment with scripts (produced with Update-Database -Script). In my latest update, I added a new column, and then in the Up() method of the migration, I added the necessary code to populate the […]

User account audit for licensing purposes

Using SQL Server 2008R2. We are trying to audit user logins to see both how long user accounts have been inactive and to see how many licenses we will need coming up. I am currently pulling information from the following job: Insert into [User_Login_Audit] Select login_name, max (login_time) as last_login_time, last_successful_logon, (select @@servername) as server_instance, […]

Summing a count of a value in SQL

I am not sure if I am doing this SQL in the best way. So hoping for any advice. I am using this query. SELECT Part_No, Serial_No, CASE WHEN MIN(Grade_Date) BETWEEN @StartDate AND @EndDate AND MAX(Grade_Date) BETWEEN @StartDate AND @EndDate THEN COUNT(DISTINCT Serial_No) WHEN MIN(Grade_Date) BETWEEN @StartDate AND @EndDate AND MAX(Grade_Date) > @EndDate THEN COUNT(DISTINCT […]

Dropping Temp Tables in a Wrapper Stored Procedure (SQL APS/PDW)

I have created a stored procedure that has many stored procedures inside of it , i.e. a wrapper procedure. The procedure does not complete because there are temp tables that have the same name between the different stored procedures in the wrapper proc. I need to find a way to drop all temp tables between […]

Automatically link objects using computation on fields with Entity Framework or SQL Server

I have two “entities”, Job Code and Job Family: public class JobCode{ public int Code {get;set;} public string Name {get;set;} } public class JobFamily{ public int Code {get;set;} public string Name {get;set;} } JobCode.Code is a 5-digit code, and JobFamily.Code is 2 digits, which correspond with the first 2 digits of a Job Code, so […]

Sql_srv query execution takes long time

I have too many tables in my database and also a huge data. in this query i’m querying from two tables, and i’m also using a function “DTtoUnixTS” to convert the date to the unixtime. but the problem is that the query takes too long time (about 6 to 7 seconds) and i have treid […]

SSIS: Transform data to fixed width text with variable rows

I’m trying to make a plain text with SSIS from a SQL select. The problem is that SSIS makes the file like a table, and I need it in a specific format. For example, I have this result: bill_id | concept |concept_type |amount | ———–|————|————-|——-| 334455 |concept1 |product |12 | 334455 |concept2 |product |10,5 | […]

How to create javascript object from SQL Server?

I have a SQL Server database I would like to parse using jQuery. My intent is that in jQuery, I can look for ID=”orange”, and it will return all the values in that row. Can you recommend a good tutorial on how to do this? I am using an ASP.NET web page with C# codebehind, […]

Merge two tables and insert/update respectively

I have two tables and I have to merge the records. source: ID seq name designation company 001 1 aaa Developer YYY 001 2 aaa lead yyy 002 1 mmm consultant bbb 003 1 ppp developer yyy 003 2 ppp lead yyy 003 3 ppp manager yyy target: ID seq name designation company 001 1 […]

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