I would like to migrate database from MS Access to SQL Server and I’m trying to modify my SQL queries. In MS Access they worked. I have this C# code: Connection method : SQL query is working but not returning rows. I guess that problem is a syntax of parameter in query. Can someone direct me? Answer You…
Tag: sql-server
Find duplicate values in a field results in multiple rows of the same values
Suppose this table I want to get all CODEs where SIZEPOS has the same value more than once… So for the product I would like to get ‘194342-01’, 10510, 5 as SIZEPOS 5 appears twice. I achieved it with the following query but for some reason some of the returned rows appear twice, or even thre…
Unable to log into Azure SQL database in Azure Portal using AAD Global Admin (member type) account
I am Global Administrator of the Azure subscription I own. Steps: I logged into Azure Portal using my credentials. I created an Azure SQL database (including initiating a new Azure SQL Server instance). I set the database security to permit both SQL Login and AAD Auth. I set my AAD account to be SQL Admin of …
One Table Update
I want to update Price where PriceGroup = ‘PG1’ and Price is null, with the Price from the same ID but the PriceGroup is PG2. I have tried a few solution here but couldn’t find any with Where statement. PriceTable: Result will be: Answer Something like this? Tried with this data and this is …
Data Architecture Question – Storing Daily Snapshot of Employee Master Data
I’m trying to store daily snapshot of Employee data for FTE analysis project – analytics on how many FTE in various positions any given day. I can call a REST API, which will give me data for all the active and terminated employees as of API call time. Is it prudent to call this API every single d…
Error Referencing Sub Query in Group By on Main Select statement in T-SQL
I am trying to run the following T-SQL code Example: Order table Item table Result: I need to be able to count the number of items for that order per month and year however, I am getting this error Column ‘Order Reference’ is invalid in the select list because it is not contained in either an aggr…
SQL UPDATE column with self referenced id from another column
I want to update the ParentId of each row that is not null With the Id from the row that has a TemplateId Matching ParentId Id ParentId TemplateID 1001 NULL 86 1002 86 41 1003 43 44 1004 NULL 43 1005 44 73 Desired results: Id ParentId TemplateID 1001 NULL 86 1002 1001 41 1003 1004 44 1004 NULL 43
Multiple location to reference location dimension
I am trying to map values associated to my location dimension – dimension seen below: LocationID Country State City Zip Code Longitude Latitude 1 USA NY Manhattan 2 USA NY Yonkers 3 USA NY Buffalo I am receiving transaction data where multiple regions may be identified as a value. For example, I will ge…
SQL Server – Can’t change datetime to date
I have this sql which has some date format issue, problem is that I can freely change EndDate to whatever I want, but for StartDate I can’t seem to change it one bit, it always have this timestamp that I am trying to get rid of. Basically whatever I do in varchar, date or any format I just can’t c…
Execute Query Inside Column From CTE
I have a CTE table which returns dynamic SQL. Here is my CTE query: which returns: I want to execute each row on the CTE table. How can I do that? Answer With just a couple of tweaks