sql-server

How can I tell if a SQL Server MDF file is getting full/might need to grow?

I know that the transaction log/ldf file fills up and grows and that I can see how full it is by running: DBCC SQLPERF(logspace) Is there a corresponding command to check on the status of the data/mdf file? Why I'm interested: I'm troubleshooting a simple .NET app that uses SqlBulkCopy to import data. Normally this works fine but ...

How to ignore bad characters in a SQL query

The short story is I have a SQL Server DB with varchar fields instead of datetime (don't ask, it's a long story and can't be fixed). Somehow we've recently been getting weird / random characters inserted in these fields instead of what should be there (either NULL, '' or YYYY-MM-DD). Something like this: '?+x' with high-bit ascii charact...

update records only when ID matches

How would I update data in a table in a separate database based on the records in the current database? For instance I want to update the field "status" in the database called "database_old" with the value contained in the database "database_new" . My current data exists in the database "database_new". I want to only update records in ...

Aggregate function in an SQL update query?

I'm trying to set the value in one table to the sum of the values in another table. Something along these lines: UPDATE table1 SET field1 = SUM(table2.field2) FROM table1 INNER JOIN table2 ON table1.field3 = table2.field3 GROUP BY table1.field3 Of course, as this stands, it won't work - SET doesn't support SUM and it doesn't support ...

sql execution plan nested loop

trying to remove the nested loop in the execution plan of a query i have (mssql 2005). have the following table: TxnID bigint CustID bigint col1 varchar(4) col2 varchar(4) col3 varchar(4) TxnCurrency char(3) TxnAmt money TxnDate datetime -- query 1 SELECT CustID, TxnCurrency, SUM(TxnAmt) AS TxnAmt FROM table WHERE TxnDate >= @dat...

Problem using a UDF as computed col: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

Hello. My question is a little subjective and might be a little unclear since I don't know where in the UDF crashes, or whether the error is caused in the function itself or from other resources using a column in this table. Let me just tell you the story. I had a function (that used as a computed-column for QuoteItemsGroupFeature.Sal...

How can I do a compare when the second is a sub select that returns multiple values?

Here's my SQL statement: SELECT DISTINCT a.* FROM OWU_Nomination as a, Merchants as b WHERE a.CallFlag = 'False' AND a.nominatedDate < DateAdd(hour, -24, getdate()) AND a.email != (SELECT c.Email from Members as c where c.MemberID = b.MemberID) The problem here is that the sub select after a.email != returns multi...

VIEWs in Entity-Framework?

Hello! I have a table called Item. I have a view called ItemView, that returns all the column of Item + one more aggregated column, that I want to be read only. I need to use it in Entity Framework, and I don't know how I should use it, since when insert the view in the designer, all the fields become entity-keys, besides no relations...

SQL UDF in WHERE condition

I want to write a query kind of like this: CREATE PROCEDURE DupFinder @FirstName varchar(20), @LastName varchar(20) AS SELECT CustId FROM Cust c WHERE [dbo].[fn_MatchConfidence](@FirstName + ' ' + @LastName, [dbo].fn_createCustHash (CustId)) > .8 Running the fn_MatchCondifence User-Defined Func...

sql database design default value

is it nesessary to add a default value to int,bit,datetime... fields? what's the benefit of having a default value? ...

Report Builder 3.0 CTP

I have downloaded MS SQL Server Report Builder 3.0 CTP recently. I am bit confused and have following questions: Can I use Report Builder 3.0 with MS SQL server 2008 Express with Reporting services (NOT MS SQL Server 2008 R2 CTP)? Is there any time limit is attached with usage of Report Builder 3.0 CTP, as it is CTP version? Generally ...

SQL query in tables side by side instead of one long table

hi there, I have ajax ReorderList in my wep page,and I get the data from SQL Server. I would like to add table cells dynamically according to number of records and show the result side by side until for example I have five data in a row and then move to the next row, any idea? Thanks in advance ...

Partition Exchange as publishing technique in SQL Server?

I'm familiar with the concept of using partitions in Oracle as a technique to pubish incremental additions to tables (in a DW context). (like this example) For example. a daily snapshot for a data mart fact table is loaded behind the scenes in a partition within a table. for example with date as the partition key (1 partitioned table...

How to convert this varchar values to a datetime

Hello people, I want to convert a varchar value that iI set up to a date time value. I want to load rows of a database into another database, but conversion is not going well. This is my query: select Krant , cast(jaar as varchar(4))+'-' +RIGHT('0'+cast(maand as varchar(2)),2)+'-' +RIGHT('0'+cast(dag as varc...

Difference between Temp Table and Table Variable In SQL 2005

Hi Can somebody explain me the difference between Temp table and table variable in SQL server 2005? ...

Sql query with functions

SELECT SLTR_COMP_CODE, sltr_ldgr_code, sltr_slmast_acno Acno, SUBSTRING(sltr_slmast_acno, 1, 1) category, ISNULL(SUM(CONVERT(FLOAT, sltr_tran_amt - ISNULL(sltr_matched_amt, 0))), 0) Net_Bal, SUM(CONVERT(FLOAT, CASE DBO.glas_agewise_analysis(CONVERT(DATETIME, '2009-04-04', 103) - FLOOR...

How can I map database table and field names back into their EF Entity object and property names?

I have a database table which records all field changes in all database tables which are mapped to Entity Framework Entities (via SQL Server triggers). I am building a service which outputs these field changes to the client. However, the client needs the EF-Entity object and property names and not the database table and field names. F...

Is there a succinct way to retrieve a list of table column names with T-SQL?

When I'm looking round a SQL Server database I often want to interactively retrieve a simple list of column names for a database table (no data type information etc., just the names) using sqlcmd. I can do this: EXEC sp_columns @table_name = 'tablename' which gives me much more than I want and wraps in a command prompt to the extent ...

How to copy an ntext column's value to a new non-null column

I have a table that has an ntext column defined as [value1] [ntext] NOT NULL. I want to add another ntext column to this table that is basically a copy of this column's values (they don't need to stay in sync). To do this, I am using the following SQL: ALTER TABLE [table] ADD [value2] [ntext] NULL UPDATE [table] SET [value2] = [value1] ...

Deleting duplicate records in a table

Hi, Consider that I am having a table named A. In it I am having only one column named marks. It has some duplicated values. How can I delete the duplicate values without temporary table. And the table should contain one of the duplicated values. ...