sql-server

How to Truncate the Decimal Places without Rounding Up?

Assume i have the following decimal value: 4.584406 I need a simple quick way to truncate the decimal without rounding up, so the output would be 4.5 I'm using T-SQL (SQL Server 2005/2008). Any help will be appreciated. ...

How to get job name and status from sql sever to textbox follow time schedule recurring

Now, i can connect MS SQL Server 2000 via connection string and get job name and job status in SQL Server Agent. but i want to show name and status continuously follow time schedule recurring for monitoring JOB. Please suggestion how to do. (using MS Visual Studio 2008 (C#)) public void ConnectJOB() { SQLDMO._SQLSer...

How do I add 'Tags' to my simple BlogPost class library & repository?

Hi folks, Update Checking StackOverflow OData service it's exactly like Posts / PostTags / Tags ... How can I replicate that, please? So I've got a simple class called BlogPost - nothing special. Just a blog post. Now, I wish to add tagging for this class. Exactly like the tags for a StackOverflow question - 5 strings, space delimit...

Get the last 24 hour job record form msdb.dbo.sysjobhistory

hi everybody, i am fresher in SQL,i want write a query to get the last 24 hour jobs record from msdb.dbo.sysjobhistory,but i cant get because,here i get the run_date and run_time as like the number.how i will convert the run_date and run_time into datetime and get the last 24 hour job record. i am using SQL Server 2000 thanks in advanc...

A very interesting problem with SQL Server Relationships (SQL Server 2008R2, LINQ To SQL, Visual Studio 2010, C#)

I'm working on a web project. I'm using a Sql Server 20008 R2 database via LINQ To SQL, and today I faced a very strange problem with relationships. I've been using them for a while and never had any problems so far. Let's say I have a table Stores that has the following fields: ID, Name, LastUserID where LastUserID is a "reference" to ...

Batch insert/update using stored procedure

Can anyone give me a sample script for batch insert/update of records in table using stored procedure in SQL Server? ...

Large table querying

Hello, I have a database table that accepts more than 2,000,000 records each month. I have created it as a partitioned table. All searchable fields are indexed. But when applying a paging select on the table by the with keyword it takes long time to get the result. Is there any other solution to tune this table's performance? ...

SQL Server Management Studio - adding foreign key confusing?

I always find it confusing to add foreign keys to primary table in Management Studio. Lets say I have a Table1 { ID int, -- Primary Key Table2ID int, -- Refers to Table2's ID } Table2 { ID int, -- Primary Key SomeData nvarchar(50) } I am adding a foreign key to Table1 by Right Click -> Relationships -> Table and...

SQL Server Management Studio - Adding/Moving Columns require drop and re-create?

Why do I get message that the table needs to dropped and re-created when I add/move columns? I believe this happens after adding foreign key constraints. What can I do to add new columns without dropping table? ...

SQL Server DB Designer/Editor - which one do you use?

I am using SQL Server Management Studio. I find it good in a few ways and frustrating sometimes. Which one to you guys use? Preferably something I can try for sometime before I buy... ...

Nested Query or Joins

I have heard joins should be preferred over nested queries. Is it true in general? Or there might be scenarios where one would be faster than other: for e.g. which is more efficient way to write a query?: Select emp.salary from employee emp where emp.id = (select s.id from sap s where s.id = 111) OR Select emp.salary from ...

Grouping Fiscal year using SQL Server

Hi, Is there a way in SQL Server that can show the Fiscal Year (begins on October 1 and ends on September 30) from a table which has a date column (1998 to 2010). Here is what I have done: select 'FY1999' as FY, site, count(*) from mytable where mydate >='10/1/1998' and mydate <'10/1/1999' group by site select 'FY2000' as FY, ...

What is the difference between composite non clustered index and covering index

SQL Server 2005 includes "covering index" feature which allows us to select more than one non key column to be included to the existing non clustered index. For example, I have the following columns: EmployeeID, DepartmentID, DesignationID, BranchID Here are two scenarios: EmployeeID is a primary key with clustered index and the re...

DATEPART not working like i think it must

select * from Advertisements where DepartureDate < DATEPART('dd.mm.yy', '09.10.2010'); but i get Msg 1023, Level 15, State 1, Line 1 Invalid parameter 1 specified for datepart. in plsql is this very simple here is so complicated... Can someone tell me please how can i get all dates that are smaller than today. ...

Best index for multiple variables to avoid an OR

hello all, i am building an application that will behave more or less like google adwords and i am at the point where i build the impression engine. we will have campaigns running based on geolocation of the user. based on his IP we will determine his state, city, approximate lat/long. on the other side we will have ads running on differ...

How Can I Split Decimal Value from Integer Value?

Assume i have 4.9 value. I would like to split 4 and .9 ... How can i do it? I could isolate 4 by using FLOOR(). What about the .9? How can i isolate it? I'm using t-sql sql server 2005/2008 ...

ms access / sql server syntax (i guess)

this query: SELECT sentmails.[VersandDatum], sentmails.[DatumMailGeplant], mailintervals.[Interval], definitions.[Subject], users.[Name], sentmails.[MailArt], Objekte.[Name], sentmails.[Erledigt], sentmails.[ID] FROM Objekte RIGHT JOIN (users RIGHT JOIN (definitions RIGH...

T-sql Cursor, what will happen in case of error?

Hi What will happen if an error occurred during a- Declaring Cursor b- Fetch data What will happen if error occurred before Cursor is closed, does it close automatically? When I use a Cursor, What is the best practice for handling errors? Thanks ...

Question Regarding Fetching Records based on Date Range

SELECT COUNT(td.timeSheetID) FROM TimeSheet t INNER JOIN TimeSheetDetail td ON t.timeSheetID = td.timeSheetID WHERE (CONVERT(DateTime, t.setDate, 23) BETWEEN '2012-08-10' AND '2012-08-12') AND t.employeeID = 300 The above code returns the value i'm looking for. However, when i do the following, i get nothing: SELECT COUNT(td.ti...

Auto generate function in SQL Server 2000

I have a table named 'Customer'. This table contains a unique Identification field for each customer named 'CustomerNo'. It should be in the format : First an alphabet Starting from A-Z. Then a four digit number starting from 1-9999 and the next is a three digit number starting from 1-999.This is a unique field.So it shoudn't repeat in...