Tag sql-server

[Solved] Relationship between tables in ms sql server [closed]

your table structure should be below PatientTable PatientId int Primary Key, PatientName varchar(50), EmailId varchar(50) Password varchar(50) TestTable TestId int Primary key, TestName varchar(50) PatientTestTable PatientId int FK(PatientTable) TestId int FK (TestTable) This way you can give relationship to two…

[Solved] T-SQL | SQL-Server Pivot [closed]

Try: select Agent, max(case when `desc` = ‘Total’ then ColValue else 0 end) Total, max(case when `desc` = ‘Replaced’ then ColValue else 0 end) Replaced from tbl group by Agent Demo sqlfiddle 1 solved T-SQL | SQL-Server Pivot [closed]

[Solved] SQL Server : how to sum? [closed]

SELECT SUM(Value) FROM TableName; Using a GROUP BY (per your comment above) is when you want things grouped over a subset. In this case, a group by would return the same info you’ve sampled, because there’s no groups to sum…

[Solved] Convert month and year columns to a date column with additional string concatination

Assuming your are using date and MSSQL2012+: SELECT UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’)) + ‘-‘ +RIGHT(CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)),2) M_DELIVERY , ‘DELIVERY FOR ‘ +UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’))+’ ‘+ CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)) AS Description Other way(using numbers and…