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…
Tag: sql-server
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:
Split column data into multiple rows
I have data currently in my table like below under currently section. I need the selected column data which is comma delimited to be converted into the format marked in green (Read and write of a …
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 …
Get “zero” for a count at dates without records
So I’m counting activity records from users in my system. I get the activity counter for each day in a certain month and year, just like the query that follows SELECT CONVERT(date, VIS_DATETIME) AS …
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.…
SQL Server – How many rows have been inserted into a table while a query is running?
I’m running a cleansing script that has 10 unions and results in, more or less, 1.2 billion rows (I’m re-executing this script including some missing fields, so I know and expect this number at the end of the execution). I’m inserting this cleaned data into a new table (X). I’ve made s…
The specified schema name either does not exist or you do not have permission to use it
I am trying to create replica of my database from SQL server to another. For that I am generating script from original server and trying to run in another server. I’ve created database manually with …