Skip to content

Tag: sql-server

LAG functions and NULLS

How can I tell the LAG function to get the last “not null” value? For example, see my table bellow where I have a few NULL values on column B and C. I’d like to fill the nulls with the last non-null value. I tried to do that by using the LAG function, like so: but that doesn’t quite wo…

how to get the ID of the record that is update in C#

I am able to get a sql query that can return the ID of a record that is update in the Database; that ID is needed to update other records. but I don’t know how to get that updated ID value in C#. Answer I think you’re really asking how do you retrieve the resultset returned by an INSERT or

Invalid Column Name using Dynamic SQL

I am attempting to use Dynamic SQL for the 1st time – Now i understand the gist of it to an extent however attempting to enter a parameter into a temp table using Dynamic SQL i am getting the “Invalid Column name” when i am simply try to enter this as text not intending to be a column. On a

Dumping SQL table to .csv C#

I am trying to implement a script in my application that will dump the entire contents (for now, but I am trying to write the code so that I can easily customize it to only grab certain columns) of a sql db (running ms sql server express 2014) to a .csv file. Here is the code I have written currently:

How to set multiple values inside an if else statement?

I’m trying to SET more than one value within the if else statement below, If I set one value it works, but if I set two values, it doesn’t work: Error message: “Msg 156, Level 15, State 1, Line 9 Incorrect syntax near the keyword ‘ELSE’.” However it seems to be possible to …

Select record between two IP ranges

I have a table which stores a ID, Name, Code, IPLow, IPHigh such as: Now, if I have an IP address 192.168.2.50, how can I retrieve the matching record? Edit Based on Gordon’s answer (which I’m getting compilation errors) this is what I have: but this gives me an error: Any ideas? Answer Painfully.…