sql-server

Check whether this condition is right or wrong

if (7/2/10 & 3/2/10) < 4/2/10 begin print ' ok' end else begin print 'not ok' end is like this can we use if condition is it possible But here in if condition i have changed whatever the dates but it only shows answer as " not ok " whether the condition is right or wrong it shows only "not ok" can some one help me ...

Help with a nested query !!

int id = 1; string chain = "("; SqlDataReader dr = SqlHelper.ExecuteReader(string.Format("SELECT a.Id as x, c.Id as y From Friends b INNER JOIN Users a ON b.SenderId = a.Id INNER JOIN Users c ON b.ReceiverId = c.Id WHERE (c.Id = {0} OR a.Id = {0}) AND State = '{1}'", id, "ok")); if (dr.HasRows) ...

What's the difference between table-based relations and column-based relations in RDBMS?

Hi, I have used column-based relations a lot in my projects like: CREATE TABLE `user` ( id INT AUTO_INCREMENT PRIMARY KEY, usergroup INT ); CREATE TABLE `usergroup` ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) ); however, at work it seems some people do it using table-based relations like this: CREATE TABLE `user` ( id INT...

Crystal Report 9 is displaying only the 1st record if records vary only by millisecond

Hi, I am using SQL Sever 2005, VC 6 ++ and Crsystal Report API to print a report in a child window. If the records vary Only by Milliseconds, Crystal Report is showing only the 1st record. Otherwise, it is perfectly fine. I am picking the timestamp from SQL Server DateTime Field. In Formula inside Crystal Report, i am only giving the...

Backup SQL Server database

Hi. I can connect to remote SQL Server database and I want to create a local database copy on my system. How can I do it? When i try backup through Management studio I cannot copy backup file on my hard drive only on remote system hard drive. Copy database command also doesn't work because I have express version of SQL Server. And exp...

T-SQL: Avoid returning result set from stored procedure

Assume I have some stored procedure (and I can't change it) which is returning a result set: create procedure test_procedure as begin select 1 end I know that I can insert result set into table, so it would be hidden to the calling code: declare @t table(i int) insert into @t exec test_procedure Are there any other ways to h...

SQL - Is it better to do a subquery here or an extended WHERE clause?

The CUST table below will be joined with ~10 tables. For this subquery in particular, am I better off simply joining up directly with the Customer table and moving the subquery's 4-part WHERE clause to the main query's WHERE clause? I'm primarily wondering if it is possible to cut down on the amount of processing that SQL Server has to...

Using CASE in Order By Clause

I have the following SQL: ALTER PROCEDURE [dbo].[SP_Products_GetList] @CatID int, @CatName int, @SortBy varchar(50), @SortType varchar(50) AS SELECT Products.ProductID, ProductName, MAX(Price) Price FROM Products INNER JOIN ProductCategory on Products.ProductID = ProductCategory.ProductID INNER JOIN ( ...

How To Move an Updated Record into a History Table?

I have the following table: CREATE TABLE FE_USER ( userid int identity (321,4) CONSTRAINT userid_pk PRIMARY KEY, username varchar(40) ); Its corresponding history table is CREATE TABLE FE_USER_HIST ( userid int, username varchar(40), v_action varchar(50) ); Every time an insert or update is occurred on FE_USER t...

SQLBulkCopy can't convert Time to DateTime

I am writing a small utility to copy a database from a proprietary ODBC database into a SQL Server database. Everything is working great, except when I use SQLBulkCopy to copy over the data. It works in most cases, but not when it's trying to copy a TIME field into a SQL DATETIME. I get this error: The given value of type TimeSpan fr...

SQL Server - Get first date in a week, given the week number?

I've got a query (for use in bug tracker.net) that calculates the number of bugs by week by status. But the query returns the week number, what I really want is the first date of the week select datepart(wk, DateAdd(day, 0, DateDiff(day, 0, bg_reported_date))) as [week], bg_status , st_name as [status], count(*) as [count] fr...

ArgumentException on Image.FromStream when reading from Database

Ok, here is the thing. My program saves an image into a SQL Server Database, the column being of image type. When I try to recover it, I get an ArgumentException from the Imagen.FromStream method. The code that inserts the image is something like this: Bitmap img = (Bitmap)pictureBox.Image; MemoryStream m = new MemoryStream(); img.Save...

How Can i Let Stored Procedure Returns Varchar Value?

Here is my sample: ALTER PROCEDURE EmpFirstName @myParam int, @empFName varchar(20) output AS BEGIN SET NOCOUNT ON; SELECT @empFName = empfname FROM FE_QEMP WHERE empno = @myParam END GO myParam is the input and empFName will carry the output, so the procedure should only take 1 parameter since empFName is the...

SQL Server: Select Max Limit 1 from Group

Using SQL Server. Ok, I'm making an in webpage cache system. I wanted to make a simple page rank system along with output. The problem is, I want to display the recordset with the highest relevance score per unique domain. One domain may have multiple records but with different titles, descriptions, etc. he probem is,instead of getting 1...

How Can I Export a Record Set to Excel from SQL Server 2008?

I have a department table filled with records. I would like to run a query or use the management studio interface to export department records to an excel file. Format is not an issue, i just want to dump the records into excel. I know i can copy and paste, but this is not what i'm looking for. ...

Question about database

Hi I have problem with two parts of database diagram and I need your guidance:) database has a lot of tables that one of them is about Employee ,the other is about Customer and ... ! I have problem with two tables (Product and OrderDetail) my Product table has 3 columns (ProductID,Name,Cost) and the Other table is OrderDetail that has th...

about triggers in sql server 2008 and 2007

Hi I need triggers window how can i find it in the sql server 2008 and 2007? thanks ...

How to update photo in gridview

Hi There, I have a gridview with employees name, there is link to another page,with employee information,when the user click on the link, according to employee id get the employee information from database, in this page we can add photos or update them,which works fine, the problem is when updating the photo, and click the link, I see ...

SQL Join Retrives more rows than expected

Suppose I have the following tables Students (StudentId int Pk, StudentName nvarchar) Lectures (LectureId Pk, StartDate, EndDate) Enrollment (StudentID, LectureID) When I execute the following query: select StudentID From Students I get 8 rows.. And when i execute: select S.StudentID From Students S join Enrollment En On S.Student...

How can I execute a stored procedure with JDBC / jTDS without using a transaction?

We run a website written in Java that uses JDBC with jTDS to access an SQL Server database. Our database contains a complex stored procedure that typically takes 10 minutes to run. The stored procedure works fine if we execute it directly (say from SQL Server Management Studio) because it does not run in a transaction. But if we execute...