sql

Cursors vs Procedures in SQL

So, I just learned about CURSORS but still don't exactly grasp them. What is the difference between a cursor and procedure or even a function? So far from the various examples (DECLARE CURSOR ... SELECT ... FROM ...) It seems at most its a variable to hold a query. Is the data real time, or a snapshot of when the cursor was declared? ...

calculate a sum of type time using sql

How to caculate sum of times of my colonne called "timeSpent" having this format: HH:mm in SQL? I am using MySQL. the type of my column is Time. it has this structure TimeFrom like 10:00:00 12:00:00 02:00:00 TimeUntil 08:00:00 09:15:00 01:15:00 Time spent total time 03:15:00 ...

Optimzing TSQL code

My job is the maintain one application which heavy use SQL server (MSSQL2005). Until now middle server stores TSQL codes in XML and send dynamic TSQL queries without using stored procs. As I am able change those XML queries I want to migrate most of my queries to stored procs. Question is folowing: Most of my queries have same Where con...

Gridview display multiple tables?

I have a gridview setup that gets its data from a SQL database stored procedure. This procedure will return one of several different tables. The gridview complains if the table is different than the one previously displayed. How do I work around this? ...

How to rewrite this SQL statement to LINQ 2 SQL ?

How can i convert this SQL query to its equivalent LINQ 2 SQL statement for VB.NET? SELECT COUNT(*) AS 'Qty', IV200.itemnmbr, IV200.locncode, IV200.bin, CAST(IV112.Quantity as int) as 'Qty2' , 'parentBIN' = isnull(MDS.parentBIN,iv112.bin) From IV00200 IV200 (nolock) inner join IV00112 IV112 (nolock) ...

Reporting Services Sum of Inner Group in Outer Group

I have a report in Reporting Services 2008 using ASP.net 3.5 and SQL Server 2008. The report has 2 groupings and a detail row. This is the current format: Outer Group Inner Group Detail Row The Detail Row represents an item on a receipt and a receipt can have multiple items. Each receipt was paid with a certain payment...

SQL Server NOT EXISTS from more than one table

Hi: I need to return rows if exists, if not return which one of the passed value is NOT EXISTS: DECLARE @INPUT1 BIGINT DECLARE @INPUT2 BIGINT DECLARE @INPUT3 BIGINT SELECT e.Name, d.Name, c.Name FROM Employee e JOIN Department d ON e.DeptID = d.DeptID JOIN City c ON e.CityID = c.CityID WHERE e.EmpID = @INPUT1 AND d.Dept...

how to have the right sum of type Time with sql

Possible Duplicate: calculate a sum of type time using sql I have 2 columns called TimeFrom and TimeUntill. The duration is calculated in TimeSpent. The values in the column TimeFrom look like this: 10:00:00 The values in the column TimeUntill look like this: 12:00:00 The TimeSpent column would then have the value: 02:00:00. ...

Linking SQL Server 2000 and SQL Server 2008, is this possible??

Hi, I am writing stored procs for a new system in SQL Server 2008 but I need to also update data in an older db - SQL Server 2000. I have searched but haven't found any solution to this. Is it possible? What are my choices? Thank you!! ...

MySQL Query That Can Pull the Data I am Seeking?

On the project I am working on, I am stuck with the table structure from Hades. Two things to keep in mind: I can't change the table structure right now. I'm stuck with it for the time being. The queries are dynamically generated and not hard coded. So, while I am asking for a query that can pull this data, what I am really working t...

What do C# Table Adapters actually return?

Hello, stack overflow ! I'm working on an application that manipulates SQL tables in a windows form application. Up until now, I've only been using the pre-generated Fill queries, and self-made update and delete queries (which return nothing). I am interested in storing the value of a single value from a single column (an 'nchar(15)' n...

Create SQL 'LIKE' Statment that looks for specific Patterns of numbers and letters

Is it possible to use LIKE in a SQL query to look for patterns of numbers and letters. I need to locate all records where the specific field data has the pattern (2 Numbers,1 hyphen, 3 Letters) ## - AAA I am using SSMS with SQL Server 2008. Any help would be appreciated. THANKS. ...

SQL Server: problem with string concatenation.

I'm trying this as part of a big query: (CONVERT(varchar(20), AZ_DTA_APP_AGE, 103) + ' ' + (CONVERT(varchar(20), AZ_DTA_APP_AGE, 108)) AS AZ_DTA_APP_AGE Why it doesn't work? I get: Syntax error near keyword 'AS' ...

calculate sum time with mysql

Possible Duplicate: calculate a sum of type time using sql Third duplicate - please stop & focus on the original question. RDBMS: mysql column names: Timefrom,timeuntill, timespent as the following type of the column:Time. timefrom timeuntill timespent 10:00:00 12:00:00 02:00:00 08:00:00 ...

TSQL Help with simple query

I'm using SQL-SERVER 2005. I have two tables as you can see on diagram, CellularUsers and CellularPayments. I need to get users who needs to be charged when there are few rules: if last CellularPayments.paymentSum of userID was 8 then select all userID and userCellularNumbers where CellularPayments.date>getdate() if last CellularPay...

Problem with Linq query and date format

Hi All I have a C# console application written using Visual Studio 2008. My system culture is en-GB. I have a Linq query that looks like this: var myDate = "19-May-2010"; var cus = from x in _dataContext.testTable where x.CreateDate == Convert.ToDateTime(myDate) select x; The resulting SQL query generates and error becaus...

SQL Query to get largest datatype in schema

What is the query to get the top 5 ...data types ...used in a DB by size? blob > int ...

Is it appropriate to raise exceptions in stored procedures that wrap around CRUD operations, when the number of rows affected != 1?

This is a pretty specific question, albeit possibly subjective, but I've been using this pattern very frequently while not seeing others use it very often. Am I missing out on something or being too paranoid? I wrap all my UPDATE,DELETE,INSERT operations in stored procedures, and only give EXECUTE on my package and SELECT on my tables,...

Problems while trying to make a query with variables in the conditions (stored procedure)

Hi!! I'm having a problem. I'm trying to do a query... I remember that in the past I did something like this but today this query is returning nothing, no error, no data, just nothing... the query is something like this: SELECT field1, @variableX:=field2 FROM table WHERE (SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX A...

Generic Database table design

Just trying to figure out the best way to design my table for the following scenario: I have several areas in my system (documents, projects, groups and clients) and each of these can have comments logged against them. My question is should I have one table like this: CommentID DocumentID ProjectID GroupID ClientID etc Where only on...