Skip to content

Tag: sql-server

Get previous value of current row in select

I am calculating value based on value in previous row. I used LAG for getting value from previous row and it works well for first two but not for next rows. Let me elaborate my scenario if row is first then I am taking Open_HA same as O column. But for next rows I am taking previous row Open_HA and

Get table name without schema

There is a string that could be a table name with ANY schema, not necessarily dbo. How do I get the table name only from the string without knowing the schema? E.g. from ‘dbo.MyTable’ I would need to extract ‘MyTable’. Answer PARSENAME can be used for this:

update with csv file using python

I have to update the database with the CSV files. Consider the database table looks like this: The CSV file data looks like this: As you can see the CSV file data some data modified and some new records are added and what I supposed to do is to update only the data which is modified or some new records

JSON Blob into SQL Server

I have data from a web API that I want to store in a SQL database. Each record in the web API looks like this: Answer That query is invalid. Should be of the form INSERT INTO TableName(Column1, Column2) VALUES (?,?), so something like:

How to combine columns, group them then get a total count?

Below is a table that has candidate_id, two interviews they attended with the interviewer’s name, and results for each interview. candidate_id interview_1 interview_2 result_1 result_2 1 Interviewer_A Interviewer_B Pass Pass 2 Interviewer_C Interviewer_D Pass Reject I need help to combine column intervi…

MS SQL Server view with conditional values

I have a table A that can reference to itself to inherit some values from a parent. The reference is represented with ParentID. Parents have null values in ParentID. ID ParentID Field A Field B Field C 1 NULL ValueA1 ValueB1 ValueC1 2 NULL ValueA2 ValueB2 ValueC2 3 1 null ValueB3 null 4 1 null ValueB4 null 5 …