sql-server-2000

Table Valued Function where did my query plan go?

筅森魡賤 提交于 2019-11-29 04:55:26
I've just wrapped a complex SQL Statement in a Table-valued function on SQLServer 2000. When looking at the Query Plan for a SELECT * FROM dbo.NewFunc it just gives me a Table Scan of the table I have created. I'm guessing that this is because table is created in tempdb and I am just selecting from it. So the query is simply : SELECT * FROM table in tempdb My questions are: Is the UDF using the same plan as the complex SQL statement? How can I tune indexes for this UDF? Can I see the true plan? gbn Multi-statement table valued functions (TVF) are black boxes to the optimiser for the outer

What exactly does the T-SQL “LineNo” reserved word do?

雨燕双飞 提交于 2019-11-29 04:46:02
问题 I was writing a query against a table today on a SQL Server 2000 box, and while writing the query in Query Analyzer, to my surprise I noticed the word LineNo was converted to blue text. It appears to be a reserved word according to MSDN documentation, but I can find no information on it, just speculation that it might be a legacy reserved word that doesn't do anything. I have no problem escaping the field name, but I'm curious -- does anyone know what "LineNo" in T-SQL is actually used for?

NHibernate paging with SQL Server

耗尽温柔 提交于 2019-11-29 01:35:39
When using SetFirstResult(start) and SetMaxResults(count) methods to implement paging I've noticed that the generated query only does a select top count * from some_table and it does not take the start parameter into account or at least not at the database level. It seems that if I instruct NHibernate to execute the following query: var users = session.CreateCriteria<User>() .SetFirstResult(100) .SetMaxResults(5) .List<User>(); 105 records will transit between the database server and the application which will take care to strip the first 100 records. With tables containing many rows this

MSSQL Select statement with incremental integer column… not from a table

独自空忆成欢 提交于 2019-11-29 00:59:06
I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer column with value = 1 for the first row, 2 for the second, and so on. This column does not actually resides in any table, and must be strictly incremental, because the ORDER BY clause could sort the rows of the table and I want the incremental row in perfect shape always... Thanks in advance. --EDIT Sorry, forgot to mention, must run on SQL Server 2000 For SQL 2005 and up SELECT ROW_NUMBER() OVER( ORDER BY SomeColumn ) AS 'rownumber',* FROM YourTable for 2000 you need to do

How to fix the embedded text qualifier issue while exporting data to CSV flat file?

試著忘記壹切 提交于 2019-11-28 18:06:05
RFC 4180: RFC 4180 defines Common Format and MIME Type for Comma-Separated Values (CSV) Files . One of the requirements of the RFC 4180 is stated as below. This is the point #7 in the RFC link. If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote. For example: "aaa","b""bb","ccc" SQL Server 2000: DTS Export/Import Wizard in SQL Server 2000 seems to conform to the above mentioned standards even though the RFC 4180 itself seem to have been published only on October 2005 . I am using the below stated

Grant execute permission for a user on all stored procedures in database?

淺唱寂寞╮ 提交于 2019-11-28 16:16:50
I generated script from old database, created a new database and imported all data from old database. So far so good, however, no user has execute rights for stored procedures. I know I can use GRANT EXECUTE ON [storedProcName] TO [userName] If it was just a few procedures, however, I have about 100 so what's the easiest way for me to grant execute access for a specific user to all of them? Thanks in advance. Create a role add this role to users, and then you can grant execute to all the routines in one shot to this role. CREATE ROLE <abc> GRANT EXECUTE TO <abc> EDIT This works in SQL Server

EF code first: Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF

帅比萌擦擦* 提交于 2019-11-28 14:29:31
I have issue with EF code first when I am trying to insert new record into table I recieve message. Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF. Any idea why I am getting the error? I am using following code: public void SaveNewResponse() { using (var context = new Context()) { var newResponse = new Response() { lngRequestLineID = 1001233, memXMLResponse = "test Response", fAdhoc = false, }; context.tblResponses.Add(newResponse); context.SaveChanges(); } } And here is my mapping public class tblResponsMap : EntityTypeConfiguration<tblRespons>

What does the pipe/veritcal bar character mean in TSQL? [duplicate]

纵然是瞬间 提交于 2019-11-28 13:58:23
This question already has an answer here: What does the pipe operator do in SQL? 4 answers Google-fu is failing me on this one. Can anyone briefly explain what the following statement would do?: UPDATE message WITH (ROWLOCK) SET message = message | 2 I found this in a trigger, and I am unable to find docs explaining what the | character does in a statement like this. That is a bitwise OR http://msdn.microsoft.com/en-us/library/ms176122.aspx It's the bitwise OR operator. See this article . Effectively, message is a bitfield, and by bitwise-ORing it with 2, you're setting the second bit. See

SQL Server: ORDER BY in subquery with UNION

被刻印的时光 ゝ 提交于 2019-11-28 13:23:43
i have two queries being combined with a UNION ALL 1 : --Query 1 SELECT Flavor, Color FROM Friends --Query 2 SELECT Flavor, (SELECT TOP 1 Color FROM Rainbows WHERE Rainbows.StrangerID = Strangers.StrangerID ORDER BY Wavelength DESC ) AS Color FROM Strangers Both of which, of course, work fine separately, but when combined with a UNION ALL : SELECT Flavor, Color FROM Friends UNION ALL SELECT Flavor, (SELECT TOP 1 Color FROM Rainbows WHERE Rainbows.StrangerID = Strangers.StrangerID ORDER BY Wavelength DESC ) AS Color FROM Strangers The query fails with the error: Msg 104, Level 15, State 1, Line

Row_Number simulation in Sql server 2000

荒凉一梦 提交于 2019-11-28 13:01:27
I have a sample input table as Declare @input TABLE(Name VARCHAR(8)) INSERT INTO @input(Name) values('Aryan') INSERT INTO @input(Name) values('Aryan') INSERT INTO @input(Name) values('Joseph') INSERT INTO @input(Name) values('Vicky') INSERT INTO @input(Name) values('Jaesmin') INSERT INTO @input(Name) values('Aryan') INSERT INTO @input(Name) values('Jaesmin') INSERT INTO @input(Name) values('Vicky') INSERT INTO @input(Name) values('Padukon') INSERT INTO @input(Name) values('Aryan') INSERT INTO @input(Name) values('Jaesmin') INSERT INTO @input(Name) values('Vick') INSERT INTO @input(Name) values