sql

How to execute sql statements from a C program?

How can I execute SQL statements from a C program. For example I want to display the output of select * from EMPfrom a c program. Do I need to do it using Stored Procedures? Do I need any library files to do it. My C compiler is Tiny C Compiler and I am currently having SQL server studio 2005. Suggestions for Unix/AIX platform + GCC are ...

How Inner Join SQL works internally

My question is not how to use inner join in sql. I know about how it matches between table a and table b. I'd like to ask how is the internal working of inner working. What algorithm it involves? What happens internally when joining multiple tables? ...

linq match word with boundaries

say i have a nvarchar field in my database that looks like this 1, "abc abccc dabc" 2, "abccc dabc" 3, "abccc abc dabc" i need a select LINQ query that would match the word "abc" with boundaries not part of a string in this case only row 1 and 3 would match ...

how to convert nvarchar to time ,not datetime ?

DECLARE @DateNow smalldatetime SET @DateNow='12:30' select @DateNow -------------------------------------OR-------------------------------------- select CAST( '12:30' as datetime ) Result: 1900-01-01 12:30:00.000 (i don't want this) But i need this result in time format not string not datetime? Result: 12:30 (i want this) ...

Exporting PDF in Reporting Services

Does anyone know if it is possible to alter the page size/scale of a report when it is displayed in PDF after an export? The problem we have is one of our users has created a report with a large number of coloumns in the table, the table then runs on to the next page of the report. We have altered the page setup to landscape within the ...

How can i create this time-table with stable time format?

How can i get result "My Dream Table Result" CREATE TABLE #temp( [count] int, [Time] nvarchar(50) ) DECLARE @DateNow DATETIME,@i int SET @DateNow='00:00' set @i=1; while(@i<1440) begin set @DateNow=DATEADD(minute, 1, @DateNow) insert into #temp ([count], [Time]) values(0,@DateNow) set @i=@i+1 end ...

ExecuteReader requires an open and available Connection. The connection's current state is closed.

Ok, I asked about this very error earlier this week and had some very helpful answers and without doubt things have drastically improved since I started following the suggestions. However, now I am using the 'correct', best practice method to access the database I still get this error on some functions and I cannot get it to disappear f...

Select distinct id when using sum on another column?

An order can consist of several rows and so the OrderId is not unique. How can I do a SUM and not have to GROUP BY in order for the SQL to parse correctly? SELECT DISTINCT OrderId, SUM(ProductPrice * ProductQuantity ) as Total FROM OrderDetails GROUP BY OrderId If I take off the GROUP BY line then I get 'OrderDetails.OrderId' is inva...

Build and display a complex composite primary key in a column

I need to build a primary key consisting of 3 sections. The first section is 3 letters long and must be an a followed by two digits eg "a00" The second section is a 3 digit unique identifier INCLUDING LEADING ZEROES, example "003" The third section is the year section of the date, eg "2008" This is all separated with dashes, so a com...

Parse year from SQL Date

I'm currently writing a Java app that interfaces with a MySQL database. My problem is that I'm trying to write a function that fills a JComboBox with the unique year-values registered in the database. I could use UNIQE on the date-field in the SQL query, but that would only exclude some of the dates, not all-but-one-date-per-year. Any he...

How can i left out join these #temp (default data) and another table?

i try to generate a table (look TABLE 1) with the query(below). CREATE TABLE #temp( [VisitingCount] int, [Time] nvarchar(50) ) DECLARE @DateNow DATETIME,@i int SET @DateNow='00:00' set @i=1; while(@i<1440) begin set @DateNow=DATEADD(minute, 1, @DateNow) insert into #temp ([VisitingCount], [Time]) values(0, right(left(conv...

How to convert datatable from UDF in SQL?

This Codes give me error:Msg 156, Level 15, State 1, Procedure DefaultActivity, Line 2 Incorrect syntax near the keyword 'RETURN'. Msg 137, Level 15, State 2, Procedure DefaultActivity, Line 3 Must declare the scalar variable "@returnTable". Msg 1087, Level 15, State 2, Procedure DefaultActivity, Line 18 Must declare the table variable "...

SQL cartesian join problem

I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key, B.Name nvarchar(250) C: C.pID primary key, C.Name nvarchar(250) There is a m to n relation between A and B (table lA_B with primary key lA_B.pID and .pInstanceA Foreign key to table A and .pInstanceB Foreign key to table B) There is a m to n rela...

Are there any platform agnostic SQL query builders with syntax, logic formatting etc.?

Are there any lightweight tools that allow easy-to-read crafting of SQL independently of the main apps/utilities associated with a particular database? I lately find myself working with MySQL, Access & now MS-SQL and use Notepad++ to build queries as it provides basic syntax highlighting that helps my unfamiliar eyes, but no logic forma...

A better way to understand stored procedures

I am trying to decypher an absolute monstrosity of a stored procedure and i'm not having much luck. Are there any free tools that will help visualise the query or at least format the syntax into a more readable format ? Any hints and tips are also welcome. The type of database i am using is MS sql server 2005 ...

Last added records in SQL-Server table

Is it possible to see when a record has been inserted in a SQL table without using a datetime column? ...

ASP.Net (C#) & MSQL -or- PHP & MySQL for Performance?

Money, Staff, Skill and preference to open source or commercial is neutral. Lets take the best of the best programmers (for arguments sake) and think about this: What will perform better overall: PHP & MySQL or ASP.Net & Microsoft SQL (I don't want biased answers, just looking for Performance, and Speed). ...

Strategies/Tools for Building Training Database

We are in the process of building a training version of our website and intranet. The sites are heavy with database interaction (update user data, track workflow, etc.) The goal is to have a small number of test accounts that people can log into and run through the tools of the site. After the session is over we would revert the data ...

MySQL/SQL: Update with correlated subquery from the updated table itself

I have a generic question that I will try to explain using an example. Say I have a table with the fields: "id", "name", "category", "appearances" and "ratio" The idea is that I have several items, each related to a single category and "appears" several times. The ratio field should include the percentage of each item's appearances out...

Advanced SQL Data Compare throught multiple tables

Hello, Consider the situation below. Two tables (A & B), in two environments (DEV & TEST), with records in those tables. If you look the content of the tables, you understand that functionnal data are identical. I mean except the PK and FK values, the name Roger is sill connected to Fruit & Vegetable. In DEV environment : Table A 1 Ro...