sql

Is this SQL select code following good practice?

I am using SQLite and will port to MySQL (5) later. I wanted to know if I am doing something I shouldn't be doing. I tried purposely to design so I'll compare to 0 instead of 1 (I changed hasApproved to NotApproved to do this, not a big deal and I haven't written any code). I was told I never need to write a subquery but I do here. My ...

how to get insert sql in mysql shell or java library?

my table is: [tableAbc] A B C ------------ 1 a b 2 c e 3 e r ... run: show create table tableAbc; to get the create table sql but how to get insert sql? like: insert into `tableAbc` ('A','B','C') VALUES(1,'a','b'); ... any idea? (or any java library to do this) thanks all! BTW: i want show the "insert sql" to web brower. so...

Compare two String with MySQL

Hi, I wan't to compare two strings in a SQL request so I can retrieve the best match, the aim is to propose to an operator the best zip code possible. For example, in France, we have Integer Zip code, so I made an easy request : SELECT * FROM myTable ORDER BY abs(zip_code - 75000) This request returns first the data closest of Paris....

Show two differents values from the same field

HI, i have two tables 1- name, id, code 2- id, value, concept One name can have two concepts and two values. i want to retreive this: Id, name, value1, value2. How can i do that? Tanks ...

Correct Way to Get Date Between Dates In SQL Server

I have a table in SQL server which has a DATETIME field called Date_Printed. I am trying to get all records in the table which lie between a specified date range. Currently I am using the following SQL DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME SET @StartDate = '2010-01-01' SET @EndDate = '2010-06-18 12:59:59 PM' SELECT ...

Sqlite in Android one table or many tables

I am creating a application that requires to store multiple attributes, and it will look up DB while running (this means multiple DB lookups). This App. should have low overhead hence, I need your suggestion whether to create multiple columns in single table or multiple tables with minimum columns. ...

Can Hibernate generate uppercase SQL?

Hi, can Hibernate generate uppercase SQL? I.e. some option which would make it send SELECT table1_.prop1_ FROM my_table AS table1_; instead of current select table1_.prop1_ from my_table as table1_; which I consider far less readable, esp. for long queries HBN tends to spit. See also https://forum.hibernate.org/viewtopic.php?f=1&...

Help with t-sql query

Based on the following table id Title Date Metadata ------------------------------------ 1 A 08/01/2010 M1 1 A 10/05/2010 M2 1 A 03/15/2011 M3 2 B 09/20/2010 M1 2 B 01/15/2011 M2 3 C 12/15/2010 M1 Input variables will be start and end date. S...

Another issue with Microsoft.SqlServer.Management.Smo.Transfer

I don't understand why sometimes Transfer.ScriptTransfer() generates a script where some CREATE VIEW statements come even before the actual table declarations. How's that possible? ...

Easy SQL Group-By question. (I'm new)

I am new to SQL so hopefully this has an easy answer. I have a Students table (studentID, name, statusID) and a StudentsClasses table (studentID, classID). I've been asked to create a view from the above tables that returns the following columns: classID: (group-by) count of students in each class AS Students count of students w...

Execute stored procedure for each record in table

I have two tables that need to be updated, Master and Identifiers: Master --MasterID (PK) --ModifiedDate --ModifiedBy Identifiers --IdentifierID --MasterID (FK to Master) --Identifier --IdentifierType --ModifiedDate --ModifiedBy The Master table's sole reason for existence is to tie different Identifiers to a single person. I receive...

mysql update table from another table

Hi, I'm trying to update a field in one table, from the sum of another field, in another table. company_tbl (PRIMARY, companySize, companyName) location_tbl (PRIMARY, companyID, locationSize, locationName) The two tables link by company_tbl.PRIMARY = location_tbl.companyID update company_tbl comp, location_tbl loc set companySize = su...

How do capture the result set from RESTORE FILELISTONLY FROM DISK... so I can query it?

How do I capture the output from the following SQL statement so I can query the resultset?: RESTORE FILELISTONLY FROM DISK = N''D:\Restores\MyBackup.BAK'' WITH NOUNLOAD, FILE = 1 Do I need to create a temporary table and then do something like?: INSERT #tmp EXEC ('RESTORE FILELISTONLY FROM DISK = N''D:\Restores\KevsP...

Error from SQL Server

Hello friends I am getting the following error while making the foreign key 'tbl_course' table saved successfully 'tbl_students' table - Unable to create relationship 'FK_tbl_students_tbl_course'. Introducing FOREIGN KEY constraint 'FK_tbl_students_tbl_course' on table 'tbl_students' may cause cycles or multiple cascade p...

Choice Between Oracle DBA and Data Analyst which one is better career option

I am very confused about making choice between being a Oracle DBA or SAS Data Analyst. I've got B.Sc.Maths degree and have decided to make inroad in computer and some friends have suggested me SAS as better option than DBA. But I have heard that DBA is money and job stability-wise better than a data analysyt. I have no very much programm...

SELECT statement for a VIEW in MySQL not returning all the wanted rows

I need help with my MySQL query: CREATE OR REPLACE DEFINER = CURRENT_USER VIEW users_phpscheduleit AS SELECT u.uid AS memberid, pass AS password, mail AS email, pv1.value AS fname, pv2.value AS lname, pv3.value AS phone, e_add, e_mod, e_de...

Use a Select Statement within a wildcard where clause

Working in MS SQL 2005 and I want to use a select statement within a wildcard where clause like so: SELECT text FROM table_1 WHERE ID LIKE '%SELECT ID FROM table_2%' I'm looking for product ids within a large body of text that is held in a DB. The SELECT statement in the wildcard clause will return 50+ rows. The statement above is o...

SQL Server 2008 Dynamic Query using CTE

I am trying to write a Dynamic Query which uses a CTE. But I am facing problems - see below This is a simplified case declare @DynSql varchar(max)=''; declare @cnt as integer; with months as ( select CAST('07/01/2010' as DATE) stdt UNION ALL SELECT DATEADD(MONTH,1,STDT) FROM months WHERE DATEADD(MONTH,1,STDT)<CAST('06/30/2011' AS DATE) ...

SQL Max Question

So I want to get the row with the most recent date, max(asofdate) but I am MySQL illiterate and can't seem to get it. It my head select * from Reports.InternalLoanExposureFlat where asofdate = max(asofdate) seems to make sense but the console seems to disagree with me. Thanks in advance. ...

t-sql select query

Based on the following table Title Jul-10 Aug-10 Sep-10 Oct-10 Nov-10 Dec-10 Jan-11 Feb-11 Mar-11 Apr-11 May-11 Jun-11 -------------------------------------------------------------------------------------------- A Null M1 Null M2 Null Null Null Null M3 Null Null Null B Null M1 Null N...