Convert bit column to integer

Try using CAST(columnName AS INT) AS IntValue. e.g. SELECT columnName, CAST(columnName AS INT) AS IntValue FROM table OR you can use CONVERT(INT, columnName) AS IntValue. UPDATE: If you need to alter the actual metadata of the table, then you first need to drop the constraints then alter the column: i.e. ALTER TABLE [Table] DROP CONSTRAINT … Read more

Can you GROUP BY with a CASE WHEN THEN alias name?

You need to use the whole CASE statement in the GROUP BY clause if you don’t wrapped it in a subquery. SELECT CASE WHEN DATEDIFF(o.EndDate, o.StartDate) < 30 THEN ‘<1 Month’ WHEN DATEDIFF(o.EndDate, o.StartDate) < 90 THEN ‘1 – 2 Months’ WHEN DATEDIFF(o.EndDate, o.StartDate) < 210 THEN ‘3 – 4 Months’ ELSE ‘>4 Months’ END … Read more

How to query nested arrays in a postgres json column?

Use jsonb_array_elements() in a lateral join as many times as the depth of a json array which elements you want to compare: select schools->>’school_id’ school_id, addresses->>’addr_id’ addr_id, addresses->>’house_description’ house_description, addresses->>’house_no’ house_no from title_register_data, jsonb_array_elements(address_data->’schools’) schools, jsonb_array_elements(schools->’addresses’) addresses where addresses->>’house_description’ = addresses->>’house_no’; school_id | addr_id | house_description | house_no ———–+———+——————-+———- 1 | 4 | 1 | … Read more

Temp Table collation conflict – Error : Cannot resolve the collation conflict between Latin1* and SQL_Latin1*

This happens because the collations on #tempdb.temp_po.OD1 and STR_IndentDetail.D1 are different (and specifically, note that #tempdb is a different, system database, which is generally why it will have a default opinion for collation, unlike your own databases and tables where you may have provided more specific opinions). Since you have control over the creation of … Read more

GETUTCDATE Function

GETUTCDATE() represents the current UTC time (Universal Time Coordinate or Greenwich Mean Time) It is a nondeterministic function, Views and expressions that reference this column cannot be indexed. The current UTC time is derived from the current local time and the time zone setting in the operating system of the computer on which SQL Server … Read more

Join Subquery result in Linq

Yes, you can join sub queries. Like this: var query = from f in db.ApplicationFees join sub in (from p in db.Payments where p.Type == 1 && p.Position == 1 && p.Date >= fromDate && p.Date <= toDate group p by p.ApplicationNo into g select new { ApplicationNo = g.Key, CNT = g.Count(), AMNT = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)