sql-server

sql- how to arrange the data in a table without use of asc keyword ?

i have a table called customer Name Id ----- ---- vimal 34 arun 56 sasi 98 if i need to arrange those data in an alphabetical order we usually use query "select * from customer where order by name asc " similarly to reverse we use the query "select * from customer where order by name desc " without use of asc and desc keyword ...

MS SQL Server, indicating VARBINARY(MAX) field's datatype in VB.NET

So, I have this scenario where I use a VARBINARY(MAX) column, because I have no idea what is going to be put into it. All I know is that as of this point in time, the data will be one of many traditional data types(Integer, String, DateTime, etc.) I also have another column that is meant to indicate the DataType so the .NET application ...

Insert media file in SQL Server

dear all How to insert media file such as *.mepeg or *.mp3 ,..... files in SQL Server ...

Can I optimize this sql Query?

Below is a sample query of what I am trying to do and it gets the job done but I feel like the sub queries are not the best way to go here. Any pointers? SELECT DISTINCT u.UserID, (SELECT COUNT(LoginID) FROM Logins WHERE Success = 1 AND UserID = u.UserID) AS Successful, (SELECT COUNT(LoginID) FROM Logins WHERE Success = ...

SQL Server keys and foreign keys

If I have a primary key in table A and in table B of the same database (table B has its own primary key) I create a relationship with the primary key in table A so that a column in table B is the foreign key, does it mean that the primary key data created in the primary key column of table A will also be added to table B by virtue of it ...

Error using Liquibase on SQL Server

I'm experimenting with Liquibase, trying to get it to copy one database to another. Unfortunately, I keep getting this error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. The SQL it's generating is here: CREATE TABLE [dbo].[Attachment] ( [Applicantid] u...

How can you tell what Tables are taking up the most space in a SQL Server 2005 Database?

How can you tell what Tables are taking up the most space in a SQL Server 2005 Database? I am sure there is some System Stored Procedure that shows this information. I have a TEST database that grew from 1tb to 23tb. We are currently doing a lot of client conversion testing in the database, which entails running the same conversion S...

checking existence of a row before doing a SELECT INTO (SQL Server)

Hi everyone, I have a SQL statement I'd like to amend. As it stands now I'm running a simple SELECT INTO but I'd like to modify it so only records that don't exist in the destination table (as determined by my criteria) are appended. Here's my initial statement: SELECT b.BallotID, m.MeetingDate INTO StagingTable FROM Ballot I...

variable column names in sql table valued function

Suppose that I am using a sql server to keep track of all my personal expenses and that I am tagging everything with a date and a category. This allows me to do things like aggregate monthly expenses per category and look at the last several months of expenses with each category as a row and the most recent months as columns. What ...

How to prevent Data Generation Plan timeout expired error

I'm attempting to populate a DB on my local SQL2008 Server using a Data Generation Plan. However, when I run it I get: Data generation failed because of the following exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.. occurred 1 time(s). I've tried setting...

login failed error when connecting to database from WCF service

Hi, I created a WCF service and one of its methods connects to database to perform some task. when I call the WCF service method from the client (website or console app), I get a login failed error ("login failed", login is from an untrusted domain"). I can connect to the database from the website successfully, but when I do the same b...

Synchronize Records using Entity Framework

I am trying to get the functionality of SQL servers MERGE statement in Entity Framework. At a WCF service, I am receiving a list of records from a client app. I want to compare a particular field in ALL the records in the list against a database table. -Should there be a matching record in the db, I need to update the other fields in t...

How to Take Part of a String using One of the T-SQL Text Functions

I have the following snippet: CONVERT(varchar, FLOOR(ROUND((DATEDIFF(minute, shiftStart.timeEntered, shiftEnd.timeEntered) - DATEDIFF(minute, lunchStart.timeEntered, lunchEnd.timeEntered)) * 1.0 / 60, 2, 1))) + ':' + CONVERT(varchar, ROUND(ROUND(DATEDIFF(minute, shiftStart.timeEntered, shif...

How optimal is this function

I'm about to implement this function to calculate some numbers. CREATE FUNCTION [dbo].[funLookupFTE] (@PFID int) RETURNS VARCHAR(20) AS BEGIN DECLARE @NumberOfFTE AS VARCHAR(20) SET @NumberOfFTE = (SELECT SUM(CASE WHEN Hours <= 20 THEN 0.5 WHEN Hours > 20 THEN 1 END) AS FTECount FROM tblPractitioners ...

A query to determine if a column is computed

Possible Duplicate: Get List of Computed Columns in Database Table (SQL Server) In SQL Server 2008 is there a stored procedure I can run or view I can query which shows whether a column is a computed column? I've tried querying information_schema.columns but it doesn't seem to provide this information. ...

SQL Server: Get table primary key using sql query.

I want to get a particular table's primary key using SQL query for SQL Server database. In MySQL I am using following query to get table primary key: SHOW KEYS FROM tablename WHERE Key_name = 'PRIMARY' What is equivalent of above query for SQL Server ?. If There is a query that will work for both MySQL and SQL Server then It will be...

Read mail from mail server

Hi all... I am creating a web application .. Through the application I will send mails to my clients(From e-mail address:[email protected])... If any client reply for my mail(To e-mail address:[email protected]) I want to read that details from [email protected] and insert into sql server database.. Please share your ideas to fix my proble...

Your first gut feeling on this SqlServer design question

We have 2 tables. One holds measurements, the other one holds timestamps (one for every minute) every measurement holds a FK to a timestamp. We have 8M (million) measurements, and 2M timestamps. We are creating a report database via replication, and my first solution was this: when a new measurement was received via the replication proc...

SQL Server Query Problem?

I was using MySQL's concat_ws function to get data from MySQL database and it was working perfectly. I discover this query through this SO Question. Now I have same case but this time database is SQL Server. Asking again for SQL Server: I have a table like this: id | roll_no | name --------------------- 1 | 111 | Naveed 2 | 22...

SQL Server table to be retrieved using ADO in VC++

I have a table with 2 columns, PatientID and TestNo. PatientID can be same for more than 1 records but the TestNo will be always distinct. I want to know the SQL statement which can fetch me the highest value in the TestNo field among all the records which has same PatientID basically max(TestNo) . I want to pass the specific PatientID ...