sql-server

Converting a serial number into date

Hallo friends, In an Excel sheet I will receive the data, which in turn I need to upload it to sql server and then implement the logic. I have received a date field --[Due Date] as number ex:-.40317. In Excel if you right click it and then format it to a date. It will show the correct date as 19.05.2010. So after uploading the file a...

Why would a stored procedure perform differently when executed remotely to locally?

We've a stored procedure that happens to build up some dynamic SQL and execute via a parametrised call to sp_executesql. Under normal conditions, this works wonderfully, and has made a large benefit in execution times for the procedure (~8 seconds to ~1 second), however, under some unknown conditions, something strange happens, and perf...

SQL Server transaction log, dbcc not really useful, ldf file not accessible, don't want to install 3rd party software

I'm trying to track down why a db query got screwed in SQL Server (just the one time). dbcc log(mydb,2) is not filterable by date(?). And the ldf file I can't access directly without going through 2 layers of bureaucracy Any suggestions? Other than installing some 3rd party proprietary log file viewer. ...

DB development in a distributed development team

The development team is geographically distributed. Of course we have code repository/bug tracking portal. As rule in our projects we use MS SQL 2005 and 2008. We do not have dedicated person who develop only DBs. Any developer of the team can contribute DB changes to the project. We needed a tool which will allow to do DB development ...

Scope of #TempTables limited to an EXEC statement?

By trying this use master go select * into #TempTable from sys.all_views select * from #TempTable drop table #TempTable exec(' select * into #TempTable2 from sys.all_views ') /* This will give error: */ select * from #TempTable2 I realized that #TempTable2 is not accessible... so using the select into #TempTable syntax is used in...

how to store 1.4666667 in sql server

How i can read this line from csv in sql server ad,aixas,Aixàs,06,42.4833333,1.466666 when i do this i got error please tell me about type for these value and a rule to add it into sql database table ...

Database reads varying dramatically on a query with indexes

I have a query that has appropriate indexes and is shown in the query plan with an estimated subtree cost of circa 1.5. The plan shows an Index Seek, followed by Key Lookup - which is fine for a query expected to return 1 row from a set of between 5 and 20 rows (i.e. the Index Seek should find between 5 and 20 rows, and after 5 - 20 Key...

Single sign on with SQL Server? Security and performance

I'm working on a website (asp.net c# with SQL Server) and the client is asking for SSO solution. I'm looking to use one shortest implementation where we can create sub-domains for different modules and install/deploy on same or different servers but all of these module/application uses same SQL Server and session is also maintained and s...

Stored Proc in sql that does not return the value

My function isn't returning anything - strReturn is empty: try { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@MerchantID", MercahntID), new SqlParameter("@LoactionID", LoactionID) }; SqlHelper.ExecuteNonQuery(DbConnStri...

SQL conundrum, how to select latest date for part, but only 1 row per part (unique)

I am trying to wrap my head around this one this morning. I am trying to show inventory status for parts (for our products) and this query only becomes complex if I try to return all parts. Let me lay it out: single table inventoryReport I have a distinct list of X parts I wish to display, the result of which must be X # of rows (1 r...

group by clause query

i have a table with values like this, i want to group by cusotmer name where as sum of the local amount should exceed 50000 else i need to delete those records which do not satisfy? how to achieve it in sql server 2005? TRN 259 3 9/9/2010 6622 68667(Rs) ABHIJIT KATARE TRN 260 3 9/9/2010 6622 14635(Rs) ABHIJIT KATA...

Semantic difference between join queries

I have two queries that I thought meant the same thing, but I keep getting different results and I was hoping someone could explain how these are different: 1. select * from table1 a left join table2 b on a.Id = b.Id and a.val = 0 where b.Id is null 2. select * from table1 a left join table2 b on a.Id = b.Id where b.Id is null ...

Stored Procedure fails when performing Update

Hi everyone, I'm using the SQL Server Driver for PHP to connect to an SQL Server 2008 Express. Right now, I'm trying to replace all SELECT, UPDATE and INSERT statements by stored procedures. This is working fine for SPs that just contain a SELECT statement. But now I tried to do one with an update, and I keep getting the error message "...

Sql Server Interview Question: What function can you NOT call from inside a stored procedure or a user defined function (table or scalar)

In a recent interview I was asked to name a built-in function(s) that cannot be called from inside a stored procedure or a user defined function (both scalar and table-value). I didn't know the answer to the question and gave the generic "I don't know but I'd love to find out." It turns out after doing a bit of research that I'm no clos...

What are the "best practices" to remove "non-unique" values from HUGE table?

Step 1: Loading data via "bulk insert" from .txt (delimited) file into Table 1 (no indexes etc.) bulk insert Table_1 from '\\path\to_some_file.txt' with ( tablock, FORMATFILE ='format_file_path.xml') Via format file I map output Column data types to avoid further conversions (from Char to Int for example) Step 2: OUTPUT the result (...

SQL notes getting joined twice because they are related to service not unit

Ok I have a database that looks as follows: Orders, Services, OrderUnits, Notes Orders: id Services: id, orderid Units: id, Orderid, unitnumber Notes: id, relatedid, text, date Orders have 1 to many order units Orders have 1 to many services Services have 1 to many notes I am trying to relate only the notes that relate to the unit ...

Split Multiple Columns into Multiple Rows

I have a table with this structure. UserID | UserName | AnswerToQuestion1 | AnswerToQuestion2 | AnswerToQuestion3 1 | John | 1 | 0 | 1 2 | Mary | 1 | 1 | 0 I can't figure out what SQL query I would use to get a result set like this: UserID | User...

SQL how to extract middle of string

I want to only get the unit number out of this string: '<p>The status for the Unit # 3546 has changed from % to OUTTOVENDOR</p>' The note is always exactly the same but the unit number changes. How do I extract just the unit number? Thanks! ...

SQLServer Calculate Average of Multiple Columns

Hi, I have generated a table using PIVOT and the ouput of columns are dynamic. One of the output is as given below: user test1 test2 test3 -------------------------------- A1 10 20 30 A2 90 87 75 A3 78 12 34 The output of above table represents a list of users ...

Interpreting an execution plan

Hello, I need some help analysing some simple t-sql execution plans. I have a table [User] with the following 3 columns: Id(Primary Key), Username(nvarchar(50)), FirstName(nvarchar(50)) I have Created an Unique NonClustered Index for the Username column The execution plan for a query filtering by FirstName: select * from [User] where...