Error during BCP import - Invalid column ordinal for field [X] in xml format...
As the subject says, I'm receiving the "invalid column ordinal" error while trying to BCP data into my database. There are no spaces in any of the column names. I suspect this has something to do with...
View ArticleHandling COALESCE and CONVERT in dynamic SQL
There is this a stored procedure that joins table to retrieve the required results. It needs to filter it by a @cha_id, and where it is not provided by the user, it will take whatever is in tablea...
View ArticleNeed help to prevent row to insert
My table and data as following,[code language="sql"]USE [myERPMARA]GOALTER TABLE [dbo].[firstTimeReg_UsrCommunity] DROP CONSTRAINT [CK_firstTimeReg_UsrCommunity]GO/****** Object: Inde
View ArticleStored proc not returning data in SSRS
Hi Experts,I am running a query below in ssms and it returns data,but when i put the same query on stored proc it returns nothing.The query must return yesterday's dataPlease helpCreate proc...
View Articlewhy did WHERE EXISTS delete the contents of whole table?
the inner query returns only 36 rows, so I expected the DELETE WHERE EXISTS to delete only 36 rows. But it deleted all data in table
View ArticleCompare Lists
Hi Everyone,Reaching out for some help solving a SQL problem. I have a list of active servers and a list of packages and which servers they were deployed to. I am trying to return a list of missing...
View Articlesent SQL query as formatted Excel .xlsx via email
I already have a working stored procedure that exports sql query data set into a .csv file and emails it. Works great.Now I need to modify it to send dataset as a formatted .xlsx report! &nb
View ArticleSELECT and UPDATE Data
Hi All,We have a table which have high data insert with a status flag column , I want to select data having status=1 and then update the status to 2. The table get inserted very frequently and now what...
View Articlewhich way is better for joins? or are both options popular?
i have a question about joining tables. I have read online people describing the two methods below..Method 1 - joining tables in a straight line (see below)Method 2- joining both tables from the first...
View ArticleUsing a local Excel file in an SQL Server query
we keep data in an Excel spreadsheet on a local drive.Can i use that data in an SQL query??I do not have permissions to create tables. I thought our previous BI Expert did this.THoughts? We want to...
View ArticleSelect latest and 2nd latest date rows per user
I have the following query to select rows where the LAST_UPDATE_DATE field is getting records that have a date value greater than or equal to the last 7 days, which works great.
View Articlehow to set value of variable = variable + string
In subject line of email I want @Subject to return "'Submission at 10/03/2019 22:46:34". Concatenating with + and quotes isn't working. How is it done?[code language="sql"]DECLARE @
View ArticleSelecting different columns of joined tables based on certain criteria
I wanted to retrieve single rows of two columns based on a certain criteria after joining multiple tables. To explain it with example, I've this: [code language="sql"] SELECT c.colu
View ArticleBCP SQL 2014 Incorrect syntax near the keyword 'in'.
Hello,When I try to run below BCP command from SSMS SQL 2014 version or sqlcmd line[code language="sql"]bcp "[db_name].[dbo].[Table]" in "Q:\Table.txt" -c -T[/code]IT gives me this error,Msg 156
View ArticleDate Range Consolidation Query
Hi there,I have a table that stores date periods against PersonID's and there should be no overlapping date periods for a given PersonID (a period starting on the same day as another ending is...
View ArticleLoading Data from Staging Table to Parent and child tables
Hi,I am trying to load data fro mSTaging table (No Primary Key as it's from the csv file) but in Child table and it's inserting all the Parent Kel column value, just picking up last value, see the code...
View ArticleGet the distinct records which having same date with different time stamp.
Hi Team,Need some on the below requirement.I have the table and data like below.create table trend(keyinstn INT,ratingdate datetime,rating varchar(10))insert into trend VALUES(4000193,'2009-03-19 02:5
View ArticleChange in row values identification
Dear Fellows,How could be find the records where specific values/field changed. In the sample table we need to find those accounts where class has been changed based on date.SQL Code for te
View ArticleRetrieve rows where specific columns are different between columns
I have the following SQL (that I got assistance on her with) to obtain both highest (max) and 2nd highest dated rows. There are some cases in the data where the only difference in the 'OLD ROW' and...
View Article