I am trying to write a SQL Server CASE statement to retrieve a student’s category based on the following condition. If the category column from the student_category table has both values ‘X’ and ‘Y’ for a student_id value from the student table, then only display the record where…
Tag: sql-server
“Column name or number of supplied values does not match table definition” when trying to upload data to my DB
this is the C# code of the query (trying to make it so I can upload images to my DB table): protected void ButtonInsert_Click(object sender, EventArgs e) { insert(); } public …
Using sum with multiple dates but keeping only the latest date
I have a table called Prospect that looks like this and I’m trying to SUM the value so that I have only 1 column for GEORGIA, ALABAMA,TEXAS and the date kept in the date field be the latest date entry. I would like to have a resultset that looks like this This is what I’ve tried, but it is not
Display all duplicated values and their IDs from a table (SQL)
I’m using SQL Sever. I have a table that looks like this: Is there a way I can retrieve all the duplicated values only? Not just one of them, but all. This is the desired output: Answer This works in SQL Server.
SQL Group by date with multiple same results
How to write a statement that groups data by date but shows when data changed for the first time date – when data changed a,b,c – some data and it can be anything This is should be the result. It might have the same data on different dates, but it missing the next day when data stayed the same. It
Query with hierarchical structure and variable number of hierarchy levels
I have table ‘Areas’ containing customer’s areas: ID, AREA_NAME, PARENT_ID Areas are organized in hierarchy up to four levels using PARENT_ID pointing to parent’s AREA_ID. PARENT_ID for top level …
Update records in SQL by looking up in different table
I am copying data from few tables in SQL server A to B. I have a set of staging tables in B and need to update some of those staging tables based on updated values in final target table in B. Example: Server B: StagingTable1: StagingTable2: After Copying StagingTable1 to TargetTable1 (ID’s get auto polu…
Issues with the view of SQL Server
I am running this query And I get this error: Error Executing Database Query. Invalid object name ‘vw_db_info’. Is there another way I get the same information without that above and I seemingly not found the view in database, not in system. Answer There is no definition of your custom view vw_db_…
Need Combined SQL Query to Update 2 Tables
I am having 2 tables. Table1 and Table2. I need to update these 2 tables based on some conditions. The SQL select query from Table1 will return multiple records, let’s name it as SQLQuery1 From SQLQuery1 results returned I need to loop through each record and execute another SQL query from Table2 which …
How to find how many times X appears
Learning SQL using SSMS and I have been given a database and a 32 questions. I am working my way through the questions and got suck on a question of “How many people live in each city?” I know how to …