Skip to content

Tag: sql-server

How do I auto-increment a alphanumeric string primary key?

Let’s say I have table A with an alphanumeric string primary key. The code used to create the table and how the table looks are shown below. I want to insert a new row into Table A and I don’t want to type out C000003 or C000004 every time. Is there a way to auto increment this? I have thought

SQL Calculating Hourly Sales

I am trying to create a SQL report that shows hourly sales. This is from my POS system. There’s a built in table that has basically all the data I need, I’m just struggling to calculate the sum of a column if they are in the same hour. Table vRPTHourlySalesPerformance (stripped down to only show r…

Using Subqueries to remove duplicate IDs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last month. Improve this question I have 2 Tables. Table 1 holds ID1 and ID2. Table 2 holds ID2 and ID3. Table 1 has unique cas…

Query using a column which contains the value of another column

I have the following table in SQL Server 2019 Note: ManagerUserID is nothing but the userid The data is How can we get user details and their manager details (they are just another user) by using one query? These are my scripts Answer You can use a subquery or a self JOIN to achieve this: Result: Optionally, …