sql

Storing time values in a database and getting the difference between two time fields

I am working on an application the stores time values in a database e.g Expected time of Arrival and actual time of arrival. What is the best way of storing these fields in a database? What SQL query can I use to obtain the time difference between the two fields? ...

SQL Server: How to list all CLR functions/procedures/objects for assembly

Question: In SQL Server 2005, how can I list all SQL CLR-functions/procedures that use assembly xy (e.g. MyFirstUdp) ? For example a function that lists HelloWorld for query parameter MyFirstUdp CREATE PROCEDURE HelloWorld AS EXTERNAL NAME MyFirstUdp.[SQL_CLRdll.MySQLclass].HelloWorld GO after I ran CREATE ASSEMBLY MyFirstUdp FROM ...

help with getting statistics from db in SQL

I'm using SQL-Server 2005. I have two tables Users and Payments which has a foreign key to Users. Both Users and Payments have a date column (Users set their value during registration and Payments gets a value during payment). Users has a column called isPaymentsRecurring as bit which tells me to renew the user or not. The value is 1 on...

sql injection in php

my query written in php is: $sql="SELECT * FROM ".TABLE_PREFIX."login WHERE username ='".$username."' AND password='".$password."'"; $res_id = mysql_query($sql); $num_rows = mysql_num_rows($res_id); echo $num_rows; When i enter a valid user name and password from a form it works ok. When i input some sql injection code the que...

Setting multiple fields in a database, from just one field...

I am working in the confines of a CMS system, which defines certain fields which can be used to make forms for use within the application in PHP. I am making use of the inputSmartSearch field, which is basically similar to Google suggest. It allows me to define an SQL query, and then displays records that match as I type in my search. ...

Does using SQL parameter binding mean text can be directly entered from input?

As the title says, if I'm using SQL parameters, ie SQLCommand cmd = new SQLCommand("select * from users where username = @user and password = @pass limit 1", Cxn); cmd.Parameters.Add("@user", SqlDbType.VarChar): cmd.Parameters.Add("@pass", SqlDbType.VarChar): Can I just enter the parameters value as the direct entry from the input? ...

How to make this sql statment

I have 2 tables: T1(IDa,IDb) : has data like this IDa IDb 1 2 3 4 5 6 7 8 and T2(IDc,IDd) : with data like this IDc IDd 1 2 4 5 3 6 7 8 and the Identity for each table is the pair of IDs: T1, Identity is IDa and IDb T2 is IDc and IDd The question is:...

SQL Inner join 2 tables with multiple column conditions and update

I am using this script, trying to join 2 tables with 3 conditions and update T1: Update T1 set T1.Inci = T2.Inci ON T1.Brands = T2.Brands AND T1.Category= T2.Category AND T1.Date = T2.Date but i encounter: Incorrect syntax near the keyword 'ON'. can't figure it out why ...

Help building an Query

Hi, I need some help building an Query. I have a table "Orders" with 3 fields (IDorder, IDcostumer and amount) and i'm trying to create an List where i add one row for each costumer with the total of amount. Can someone help me building this query? ...

Understanding ROLLUP in SQL

I've figured out CUBE as just generating all the permutations, but I am having trouble with ROLLUP. There don't seem to be any good resources online or in the book I'm reading for explaining SQL for people like me who struggle with it. My book says that ROLLUP is a special case of the CUBE operator that excludes all cases that don't fol...

Using PHP + VoltDB together?

Hi everybody, Is there any way to use voltDB in a PHP application? It definitely seems like it have a few advantages over other Databases out there! ...

SQL Server trace - translating PAGE information to actual resource

I am researching deadlocks that are happening in our application. I turned trace on for 1204, 1205 and 3605. I got the deadlock trace alright. But I am unable to figure out the resource it is deadlocking on. I have read many forums and they all say that the trace should contain something called a KEY/RID which would point to the resource...

Running stored procedures

Hi, What's the best way to know which stored procedure are currently running in a database. I have a stored procedure which basically calls other 3 and passes them some parameters and these 3 stored procedures take a long time to complete... I would like to know which one is running... Thanks ...

database paging design

I'm fetching data for my grid like this SELECT Orders.CustomerID, Orders.OrderTime, OrderItems.ProductID, OrderItems.Quantity FROM dbo.Orders INNER JOIN dbo.OrderItems ON Orders.ID = OrderItems.OrderID I also need the total count for the pagination. There're two options. 1- Do an another fetch SELECT count...

Why do we have to make a SELECT after an 'INSERT ALL'?

As I seen on many sites, if I want to make an INSERT ALL, I have to finish it with a SELECT (Like SELECT * FROM dual;) Why? ...

SSRS parameter - Upload text file?

HI, Can you upload a file as part of sql server reporting service 2008 parameter? I would like to be able to upload a text file list contract ids and produce a report based on those contracts. e.g for these 100 contracts what date were they entered into the system. I could have a parameter field which takes a list of comma separated ...

Why does VARCHAR need length specification?

Why do we always need to specify VARCHAR(length) instead of just VARCHAR? It is dynamic anyway. UPD: I'm puzzled specifically by the fact that it is mandatory (e.g. in MySQL). ...

can't find the type 'bigint' in Sybase ASE 12.5.4

Hi is bigint supported in Sybase ASE 12.5.4 ? if not is there any equalent to bigint in Sybase ASE 12.5.4 ? ...

Using a single common WHERE condition for UNION in SQL

I am trying to do something like this: SELECT a.date AS EnrollDate, a.id, a.name, b.address FROM student a JOIN Location b ON a.id=b.id UNION SELECT a.date AS EnrollDate, a.id, a.name, b.address FROM teacher a JOIN Location b ON a.id=b.id WHERE a.date>'2010-01-01' ORDER BY EnrollDate But the WHERE condition applies to the se...

Mysql - can I have a View that is an in memory image of a table

I have a table with about 3000 records that I query often. Does mysql provide some sort of View that can load the table in memory and stay synced with my table (similar to a cache), so i can query this view and have really fast results? ...