Skip to content
Advertisement

Tag: sql-server

Adding a SQL column while also filling it in with a value from each row

I have a table with a column LastUpdated of type DateTime, and would like to add a column LastUpdated2 to this table. I would like to populate it with whatever LastUpdated is for each existing row in the table. Eg: LastUpdated 12:01 PM 5:00 PM Becomes: LastUpdated LastUpdated2 12:01 PM 12:01 PM 5:00 PM 5:00 PM Quite simply as you

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 relevant info): dt_when create_hour_ordinal c_ticketitem_net_price

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 cases for ID1 and multiple cases

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, you can add

Advertisement