sql

Loop in a sql query

Hi, In my Sql database, I have tables 1 Account_Customer -AccountID -CustomerID -Account_CustomerID 2 Accounts -AccountID -Balance 3 Customers -CustomerID -Name -Sex -Age 4 Loans -LoanID -Amount -BranchName 5 Loan_Customer -Loan_CustomerID -LoanID -CustomerID and I want to write a stored procedure for Listing customers togethe...

MySQL "ORDER BY" the amount of rows with the same value for a certain column?

I have a table called trends_points, this table has the following columns: id (the unique id of the row) userId (the id of the user that has entered this in the table) term (a word) time (a unix timestamp) Now, I'm trying to run a query on this table which will get the rows in a specific time frame ordered by how many times the colum...

Fetch records from one table where there's not a record in another

SURVEYS table: SurveyID UserID Question Choice1 Choice2 Choice3 RESPONSES table: UserID SurveyID Answer The first desire (achieved): Show me all surveys that User 28 has initiated: SELECT * FROM Surveys WHERE Surveys.UserID = 28 The second desire (achieved): Show me all surveys that User 28 has answered: SELECT * FROM...

LINQ queries: SQL-style abbreviations or spell it out?

Microsoft is pretty clear that .NET "identifiers" or "parameters" should not contain abbreviations. Straight from the horse's mouth: To avoid confusion and guarantee cross-language interoperation, follow these rules regarding the use of abbreviations: Do not use abbreviations or contractions as parts of identifier names. For ...

Insertion of data after creating index on empty table or creating unique index after inserting data on oracle?

Which option is better and faster? Insertion of data after creating index on empty table or creating unique index after inserting data. I have around 10M rows to insert. Which option would be better so that I could have least downtime. ...

Check if a variable is null in plsql

I want to check if a variable is null. If it is null, then I want to set a value to that variable: //data type of var is number if Var = null then var :=5; endif But I am geting error in it. How can I check if a variable is null? I am using oracle data type ...

Protecting strings within a Delphi application

We have a Delphi 2006 application that drives a MS SQL Server database. We have found a vulnerability where it is possible to load the executable into a hex editor and modify the SQL. Our long term plan is to move this SQL to CLR stored procedures but this is some way off since many of our clients still use SQL 2000. We've thought ab...

LINQ to SQL Downside and Limitations

What are the downsides and limitations of using Linq to Sql verses writing a more traditional data layer calling stored procs/using dynamic sql through the .NET SQL Server data provider? The advantages are well documented but I’ve found little discussion of the real world issues people have experienced. Please note I’m not talking abou...

Can I have problems with SQL @@identity and no triggers ?

The code ALTER PROCEDURE [dbo].[spSocial.QuestionsAddNew] @IdUser int, @IdQuestionCategory int, @Title int, @Body int, @CreatedDate int, @ActivityDate int, @VotesCount int, @AnswersCount int, @ViewedCount ...

QA: Structure, Performance of this QueryBuilderClass

Hi there, I build this little helper class to try class chaining in PHP to build SQL (atm very simple SELECTs) queries very easily. Any ideas or complaints about it, or tips for the future? class SQLQueryBuilder{ public $query; public $parameters = array(); const SELECT = 'SELECT '; const FROM = ' FROM '; const WH...

SQL Server - Can you add field descriptions in CREATE TABLE?

I can see plenty of posts about where the field description extended property lives and how I can get it, but nothing about adding these at the CREATE TABLE stage. I'm dynamically creating tables so dynamically adding field descriptions would be a tidy thing to do but I cannot see a way. Has anyone managed to do this? ...

Generaly in database design what is better one table with two references or one table?

Let's say i have people who search for jobs, and i have a list of jobs. So i have two tables: people and jobs. Now i have a list of skills of the person, and i have a list of skills for the job requirement. What is better to have ONE skills table like this: CREATE TABLE skills_reference ( id INT, reference_id INT, -- can reference peop...

Testing for existence of a column

Say I am not sure if table t in database d has a column x or not. Perhaps this is because some of the databases the application uses have been upgraded and some have not, so some have t.x and some don't. Now say I just need a simple query to get a row from d.t and I want the value of d.t.x if the column exists and some default if not. ...

Best Way to Generate Unique and consecutives numbers in Oracle

I need to generate unique and consecutive numbers (for use on an invoice), in a fast and reliable way. currently use a Oracle sequence, but in some cases generated numbers are not consecutive because of exceptions that may occur. I thought a couple of solutions to manage this problem, but neither of they convincing me. What solution do ...

sql split string by space into table in postgresql

I looking for a function like regexp_split_to_table, but our db is version 8.2.9, so it doesn't have it. I'm really only splitting on a space, so a string like how now brown cow would return +------+ |Column| +------+ |how | |now | |brown | |cow | +------+ is there a simple function that can handle this, or something I ...

What's the proper name for an "add-on" table?

I have a table a with primary key id and a table b that represents a specialized version of a (it has all the same characteristics to track as a does, plus some specific to its b-ness--the latter are all that are stored in b). If I decide to represent this by having b's primary key be also a foreign key to a.id, what's the proper termin...

how to delete one of the two duplicate records in db2 database.

I have a requirement where i have two records with same value except the PK. how can i delete one of them.I have plenty of such duplicate records. ...

SQL Question ... should I use a Group By???

I have a situation where I need to group data by a portfolio name, then sort through the data and display check boxes. Here's the table structure. Table A -------- portfolio_id portfolio_name Table B ------- file_id portfolio_id (Foreign Key fk_port_id references portfolio_id in table A) file_name Basically Table A links to table B ...

Coldfusion, outputting SQL results grouped by Date Grouping, Today, Yesterday, This Week, etc...

Hello! I'm hitting the DB for a 100 records from a MySQL DB that have a DateAdded (timestamp) column. I'd like to find a SMART way to display the records as follows in Coldfusion, w/o hitting the database multiple times. Today: - records..... Yesterday: - records..... Earlier This Week: - records..... Earlier This Month: - records.......

Can you execute multiple SELECT statements on a MySQL DB?

How do I execute a query like this using PHP: SELECT [name] FROM [items] WHERE [ID]=1, [ID]=2, [ID]=3 and have MySQL return me all 3 rows? ID name -- ---- 1 John 2 Jane 3 Jack ...