Tag: sql-server

SQL – Joining to Nonexistent Records

After doing a bit of looking, I thought maybe I’d found a solution here: sql join including null and non existing records. Cross Joining my tables seems like a great way to solve my problem, but now I’ve hit a snag: Below are the tables I’m using: CREATE TABLE [dbo].[DCRSales]( [WorkingDate] [smalldatetime] NOT NULL, [Store] […]

SQL Server: How to find the result with 2 criteria: one equals certain column; the other doesn't equal another column

I got a question as shown in pic: SKU is unique, its name can get different sizes. I want to use SQL Server to display its other size (with same NAME). How can I achieve it? Many thanks in advance.

Write CASE condition for one column in the Query

I have a query in which, I want to apply CASE condition. This is my query: Select a.mkey, a.party_name, a.doc_no Inward_No, c.type_desc Doc_Type, a.ref_no, convert(varchar(25),a.ref_date,103) Ref_date, a.Inward_amt, b.first_name + ‘ ‘ + b.last_name ToUser — here from inward_doc_tracking_hdr a inner join user_mst b on a.To_User = b.mkey inner join type_mst_a c on a.doc_type = c.master_mkey […]

T-SQL return a row if another row doesn't exist

Let’s say I have this table (this is simplified, of course there are other columns): CompanyID (int) ContactName (varchar(50)) ContactType (char(1)) with the values: CompanyID | ContactName | ContactType ———————————————– 1 | John Doe | A 1 | Jane Smith | B 2 | Ralph Jones | B 3 | Dick Grayson | A What […]

Does SQL compression of “None” clean up a data table?

I’m experimenting with reducing the storage for a SQL Server database that’s over 4 GB and growing. I opened the Data Compression Wizard in SSMS, selected compression type of “None” on the largest table, and clicked the Calculate button. I was surprised that the result was less than half the original (2.2 GB down to […]

Grails Domain Update vs Database Trigger Update

I have 2 tables, first one is parent table and second one is child table. Table Employee: Emp_Id, Name, Age, Salary, Travel_Allowance, Cost_To_Company Table Allowance: Id, Emp_Id, Type, Amount Here I need to update Travel_Allowance column of Employee table whenever a row inserted/updated for Travel_Allowance type record in Allowance table. For this I have written […]

Check a word starting with specific string

I try to search on a string like Dhaka is the capital of Bangladesh which contain six words. If my search text is cap (which is the starting text of capital), it will give me the starting index of the search text in the string (14 here). And if the search text contain in the […]

SQL update only when non null

UPDATE main SET main.PCH_2YR = (SELECT TOP 1 sub.PCH_2YR FROM [dbGlobalPricingMatrix].[dbo].[tblPCHLookup_Test] sub WHERE sub.capid = main.capid AND sub.milespa = main.mileage AND sub.maintained = main.maintenance AND sub.pch_2yr IS NOT NULL) FROM [dbWebsiteLO3-PRICING]..Vehicles_Staging_Data main I only want to set the value if the subquery returns a value that isn’t NULL. How can I do that? Only one […]

C# Connecting to SQL Server using exe

My goal is to create a stand-alone C# Windows form application which will connect to SQL Server. I have to deploy this stand-alone file in different client machine. Consider I have two machines – Machine A and B. On Machine A, I have installed SQL Server 2008 R2 and VS2013 for development. Connection string I […]

Windows Identity Impersonation not persisting into Sql Trusted Connection

I’ve inherited a WCF web service that uses impersonation to connect to the database, while trying to get the automated tests running I noticed that any of these hitting the test instance of the service were failing with a 401 response. Using Fiddler to capture the response I was able to see that it was […]

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