For this question, I am referring to the specific case where you have table T, it has primary key K, but K is a foreign key. Is this valid? And how would you write it in SQL99? All the other …
How to convert varchar to datetime, not working
I have imported some columns from a textfile into my table stuff. I had to import date as varchar(255). I want to convert datatype from varchar to datetime. The format of date data is: 6/2/2018 3:…
SQL Server – Create view using many fields of a row as names of columns
I present to you a simple and short example of what I want to resolve. I need to create a view from two tables. The table indicator stores in a single row the names of the indicators to be measured …
Cognos SQL WITH clause generating syntax error
I have an SQL query I’m running in Cognos 11 and am trying to use a WITH clause but keep getting an error for incorrect syntax near “WITH”. I thought my org admins had disabled WITH but I have …
T-SQL – Copying & Transposing Data
I’m trying to copy data from one table to another, while transposing it and combining it into appropriate rows, with different columns in the second table. First time posting. Yes this may seem …
Count Male and Female in SQL and how many records are there. With male listed with their name
I have a table Company, and I want to group the entries by Male and Female. And I want their names listed in a column. The result should like as shown here: +——–+———-+——————-…
Update Primary Key Column Name in SQL
This code defines Category table in SQL: CREATE TABLE [dbo].[Categories] ( [CategoryID] INT IDENTITY (1, 1) NOT NULL, [Name] NVARCHAR(450) NULL, […
Oracle: How to update every row in a table within the procedure if rows are grouped?
Imagine I have a table with dublicates (I have simplified the problem and data): My procedure with Parent_id as a parametr goes through every row and find value for ‘Matched’ column in a different …
Get HIGHEST and SECOND HIGHEST value for each ID (SQL)
New to SQL. In Access 2016. In a table of different equipment (EQUIP1, EQUIP2, EQUIP3), I want in a query the last and second to last maintenance dates. Many fixes I have searched for do not account for grouping by an ID (EQUIP# in my case) What I have: What I need: EDIT: Thanks! Got a little caught up on
Replace 0 in one field in case statement result that is stringing fields
I have a statement like the following: select distinct s.field1, s.field 2, Case when s.intfield3 = 2018 then (RTRIM(cast(s.intfield4 as char (2))) +’/1/’+ cast(s.intfield3 as char (4))) when c….