SQL table transform

I have Table A customerID Product ------------------- 101 A 101 B 102 B 102 C Want to transform it to a Table B like: customerID ProductA ProductB ProductC --------------------------------------- 101 1 1 0 102 0 1 1 My ultimate goal is to leverage th

LEFT join returns only NULL for the right side

I am facing a problem with a join query with two conditions. the problem is that the query only gives back the left site, whereas the right site only contains NULL. I checked that the types of the data match. What could be going wrong? SELECT t2.YEAR

Corresponds to multiple key / value pairs in SQL

I have metadata stored in a key/value table in SQL Server. (I know key/value is bad, but this is free-form metadata supplied by users, so I can't turn the keys into columns.) Users need to be able to give me an arbitrary set of key/value pairs and ha

SQL Inner Join With Multiple Columns

I've got 2 tables - dishes and ingredients: in Dishes, I've got a list of pizza dishes, ordered as such: In Ingredients, I've got a list of all the different ingredients for all the dishes, ordered as such: I want to be able to list all the names of

How to use JPA with a random database, ie the user submitted

I am using UCanAccess and was setting up my Entities and Persistence Unit when I realized that the DB location is hard coded into the PU.xml (which is fine to build my entities, but I need to have it variable). I am creating an application that will

SQL gets most successes to the specified date-date

Need help of making a SQL query which would give me rowcount on simultaneous logged in users in specified period (like last week, or last month). I need to get the date and count. SQL table has these columns: ID(indentifier, numeric) Username(varchar

change of data type in the entire database

By mistake I have created my tables with data type int(200), varchar(200), double(200,2) in MySQL. Now I want to change it to int(20), varchar(20), double(20,2). Since the database is very big changing them one by one is a very very difficult task. I

MS-SQL - Extracting a numerical part of a string

I have an MS-SQL table, with a column titled 'ImportCount'. Data in this column follows the below format: ImportCount [Schedules] 1376 schedule items imported from location H:\FOLDERA\AA\XX... [Schedules] 10201 schedule items imported from location H

Count query does not work in store

I am trying to select no of rows returned by select statement, but it returns 0, otherwise if I run simple count query, then it returns no of records being found WHY doesn't SP work for me ??? SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE P

SQL query by adding two columns in the where clause?

I have a database table that contains two scores: scoreA scoreB I am trying to make a SQL query by adding these two values, such as SELECT *,(scoreA+scoreB) as scoreC FROM data WHERE scoreC > 100 ORDER BY scoreC DESC However, it shows an error: ERROR

Call function only times for multiple locations in a query

SQL Query SELECT dbo.TotalPackagedQty(t1.int_PackingListDetailId), float_Quantity, int_PackingListDetailId CASE WHEN dbo.TotalPackagedQty(t1.int_PackingListDetailId) = 0 THEN 1 WHEN dbo.TotalPackagedQty(t1.int_PackingListDetailId) < float_Quantity TH

Adding an account from another table to an existing query

This query is working fine: SELECT posts.titulo as value, posts.id as id, posts.img_src as img, posts.id_familia, posts.tiempo, posts.votos, familias.clave, familias.id as fm, textos.clave, textos.texto as familia, FROM posts,familias,textos WHERE po

How to clone an entry in a column at all with the same ID?

I'm looking to clone an entry in a database while the id is the same. Each line has its own ID, and then a separate column for the entry I'm looking to duplicate. I'm trying to find any entry with data in this column, and clone it to any other lines

SQL: Select a list of & ldquo; nothing & rdquo;

What is a fast/readable way to SELECT a relation from "nothing" that contains a list of numbers. I want to define which numbers by setting a start and end value. I am using Postgres SQL and SQLite, and would be interested in generic solutions th

2 seal left seal 1 table

SELECT * FROM dvcam LEFT JOIN format AS format1 ON dvcam.ID_Format=format.ID_Format, originaltape LEFT JOIN format AS format2 ON originaltape.RO_Format=format.ID_Format Can anyone help me with this? Format contains ID_Format and Format where is saved

Find a text in a stored procedure in SQL Server

I want to search a text from all my database stored procedures. I use the below SQL: SELECT DISTINCT o.name AS Object_Name, o.type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id = o.object_id WHERE m.definition Like '%[ABD]%'; I

How do I invert the status column pass / fail in a query?

I am having a table as: sid sname status 101 abc pass 102 cda fail 103 fgh pass 104 hij pass 105 jqk fail 106 lfj fail and I want a output as: sid sname status 101 abc fail 102 cda pass 103 fgh fail 104 hij fail 105 jqk pass 106 lfj pass select sid,

Does Jooq have a superior performance to simple sql in java?

I want to use jooq for my java web project because from its specifications it seems simple and good query builder but does it has any performance gain over simple query or prepared statements in java.No, it does not offer performance gain. JOOQ itsel

LINQ - View about 6000 unique records by the WHERE clause

I've got a problem and no idea how to solve it. Imagine you have a List<int> with about 6000 unique id's that matches the id's of a table with about a million records in a sql datatable. I want to select those 6000 records that matches those id's vi

How is SQL query writing for reports different?

How does writing SQL queries for reports, which often are just run once a week, once a month or some infrequent amount, differ from writing queries for web applications (or applications) which are run many times a day? If a query runs only once a mon

Subquery returned more than 1 to handle it

My SQL Query is select ID, ModuleID, (SELECT ((CAmount * CPercentage)/100) FROM Table1 ) as Percentage from Table1 order by ModuleID ; It works perfectly if there is only one value but if there is more than one value i get an error. how to handle it,

How to write a condition case if in the stored procedure

i have an table where i am passing 5 paramter table name=" image" parameter @imageID, @imageName, @imageDirectory, @imageResource, from the front end [from page that is from textbox control] if they didnot send any values to stored procedue then

Conditional joints - Dynamic SQL

The DBA here at work is trying to turn my straightforward stored procs into a dynamic sql monstrosity. Admittedly, my stored procedure might not be as fast as they'd like, but I can't help but believe there's an adequate way to do what is basically a