sql-server-2005

Entity framework and VARBINARY

霸气de小男生 提交于 2019-12-19 06:56:08
问题 I’m using the .NET entity framework and I’ve got one entity containing a varbinary. Is there an easy way to get the size of the varbinary in the codebehind, efter it’s been retrieved from the database? I’m thinking there might be some way to get the size directly from the entity, something like entity.Context.Size – or do one need to handle it differently? 回答1: A varbinary translates to a byte[] field in Entity Framework, which means you can check the Length property of the array: int

Skip first row in SQL Server 2005?

时间秒杀一切 提交于 2019-12-19 06:16:28
问题 We can select Top 10 or Select Top 'N' row from SQL Server. But is there any way to skip first row from the result of top?? I mean I get result from select top 5 , then I skip the first row and get only next 4 rows? 回答1: You can use OVER clause and a ranking function. You can't filter on this directly so you need to us a sub query or a common table expression, the example below uses the latter. DECLARE @MyTable TABLE ( ID INT, Name VARCHAR(15) ) INSERT INTO @MyTable VALUES (1, 'Alice') INSERT

How do I use SQL Server table name in select query with a variable?

主宰稳场 提交于 2019-12-19 06:14:11
问题 Is this incorrect, can't we pass the table name to a select query dynamically? This is giving me a error 'Must declare the table variable @TblName' DECLARE @TblName VARCHAR(30) SET @TblName = 'User' SELECT * FROM @TblName 回答1: You need to create a dynamic SQL query, preferably using the QUOTENAME function. You can avoid any issues from malicious input by using QUOTENAME function. Here is a sample script that illustrates how to query a table by creating a dynamic SQL query by passing in a

How do I update n rows in a table?

。_饼干妹妹 提交于 2019-12-19 06:05:32
问题 I need to update the first N rows in a table meeting a condition. I know I can do an Update Top N... but the problem is that N is in a @variable. UPDATE TOP @N SET ... doesn't work. Is there a way to do this that I am just missing? No specific table definitions here because it doesn't matter what the columns are.. If I can do it for a one column table I can do it for my table. 回答1: You need to use parens after TOP clause when you want to use a variable: UPDATE TOP(@N) ... 回答2: WITH q AS (

How do I update n rows in a table?

懵懂的女人 提交于 2019-12-19 06:04:44
问题 I need to update the first N rows in a table meeting a condition. I know I can do an Update Top N... but the problem is that N is in a @variable. UPDATE TOP @N SET ... doesn't work. Is there a way to do this that I am just missing? No specific table definitions here because it doesn't matter what the columns are.. If I can do it for a one column table I can do it for my table. 回答1: You need to use parens after TOP clause when you want to use a variable: UPDATE TOP(@N) ... 回答2: WITH q AS (

Optional parameter in SQL server

自古美人都是妖i 提交于 2019-12-19 05:32:07
问题 I have a user defined function which is used in many stored procedures which will return me some value. If it possible for me to add a new optional parameter to the same. If I don't pass any value it should be null and if I pass some value it should take it. I don't want to go and change all the stored procedures to do so. Example code dbo.CalculateAverageForUser(userid int) Can I use dbo.CalculateAverageForUser(userid int, type NVARCHAR(10) = NULL) 回答1: If you don't want to go adjusting all

What is maximum allowable value of “Max Pool Size” in sql connection string

旧城冷巷雨未停 提交于 2019-12-19 05:16:52
问题 What is the maximum allowable value of "Max Pool Size" in a connection string? Suppose this is my connection string in app.config <add name="Name" providerName="System.Data.SqlClient" connectionString="Data Source=ServerName;Network Library=DBMSSOCN;Initial Catalog=DatabaseName;user=UserName;password=Password;Max Pool Size=1024;Pooling=true;"/> What is the maximum value I can use instead of 1024? Remember it is maximum value, not default value. 回答1: There is no documented limit on Max Pool

Does SET NOCOUNT ON really make that much of a performance difference

让人想犯罪 __ 提交于 2019-12-19 05:16:19
问题 In this article, the author suggests that there is material overhead associated with SET NOCOUNT ON and that "By removing this extra overhead from the network it can greatly improve overall performance for your database and application" The author references a change in the default stored procedure template from 2000 to 2005 and suggests that "Microsoft even realized the issue " which prompted the change in this template. Does somebody have hard evidence that either supports or refutes the

SQL Server Import wizard fails with incomprehensible message

时光怂恿深爱的人放手 提交于 2019-12-19 05:14:15
问题 I just want to import two columns from a flat file into a new table. I have set one column, 'Code', to be varchar(50) , and another column, 'Description', to be nvarchar(max) . The import fails with the following messages: - Executing (Error) Messages Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "Description" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.". (SQL Server

Why doesn't SQL Full Text Indexing return results for words containing #?

别等时光非礼了梦想. 提交于 2019-12-19 05:04:33
问题 For instance, my query is like the following using SQL Server 2005: SELECT * FROM Table WHERE FREETEXT(SearchField, 'c#') I have a full text index defined to use the column SearchField which returns results when using: SELECT * FROM Table WHERE SearchField LIKE '%c#%' I believe # is a special letter, so how do I allow FREETEXT to work correctly for the query above? 回答1: The # char is indexed as punctuation and therefore ignored, so it looks like we'll remove the letter C from our word