Tag: sql-server

Self Join table to identify new records by date

I have a table that updates daily with new invoice lines by date. However, each new day will contain ALL of the invoices from the previous days. 1-1-2017 will contain all invoices as of 1-1-2017, but 1-2-2017 will contain all new invoices as well as the invoices from 1-1-2017. Here is an example below. I […]

Error Connecting To SQL using VBA Code Without Using Windows Authentication

I am trying to connect to a SQL via VBA Code on Excel. The problem is that when I am logged in on my username, I can connect to the database without problem. But when I try to connect with other user logged in, the connection is unsucessful. I have already created a user inside […]

Insert data into SQL Server database from an Excel file

I’m trying to insert data to database using excel file. This code works fine for me. But I used this with windows form application. How can I change this code to WCF? I need to open Excel file using Windows Forms application and then pass the value to WCF service to insert data into the […]

Case Statement With Multiple Joins

I have two tables, emp and location. I need to fetch the records for all the matching eid s’ of emp table based on location type. If the location type=2 then we need to fetch the city associated with it. If we don’t have type=2 record we need to fetch type=1 associated city for the […]

How to combine these 2 SQL query results?

1st Query: Select O.TrainDate, O.RailHead, O.Position as Pos, O.Iso, C.CustomerName + ‘ (‘ + O.Customer + ‘)’ as Customer, P.ProductName + ‘ (‘+O.Product +’)’ as Product, O.Target, O.Docket, o.Gross, o.Tare ,o.Net, o.ConNote, o.Description from IsoOrders O, Customer C, Product P where o.Customer = c.Customer and p.Product = o.Product and o.Traindate >= ’12-14-2016′ and o.Iso = […]

Filtering consecutive dates in SQL Server

I would like to filter consecutive dates from my holiday table if any of the consecutive date is yesterday. Below is my code to get consecutive dates with row numbers. SELECT RW = ROW_NUMBER() OVER( PARTITION BY GRP ORDER BY HolidayDate), HolidayDate FROM (SELECT HolidayDate, DATEDIFF(Day, ‘1900-01-01’, HolidayDate) – ROW_NUMBER() OVER (ORDER BY HolidayDate) AS […]

Comparing VARCHARs of different length

I’m writing a stored procedure and I need to compare a SQL Server variable to a column. The problem, is that if my SQL variable is a VARCHAR that’s not the same length as the column type, it won’t match. Example: Let’s say, I have a table types with a column name that has a […]

How to get value of DataTable Row in C# asp.net

i am learning asp.net with c# by myself, and i have a problem with DataRows, in db i have users table and there is isadmin column which value is int, i want to redirect users to different page and admins to admin page, but the problem is all users redirects to admin page. Here is […]

Get top n row of each group of two columns

This question is different from Get top 1 row of each group. In my question, each group is consists of two columns (col1, col2), while in his question each group is consists of only one column (col1). I also tried to modify the answer in his question but failed. Example: Suppose n = 1 Input: […]

Sql result return value when one of the rows has a certain value

I have a query that is returning some data that looks similar to this: Select DISTINCT ID_NUM, CRS_ID, ACTION FROM MY_TABLE The data returned looks like this: ID Num | CRS_ID | ACTION 1111111|ABC_DEF | C 1111111|ABC_DEF | D 1111111|GHI_JKL | C 2222222|ABC_DEF | C 2222222|GHI_JKL | C I need to manipulate the data so […]

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