sql-server-2000

Use a variable for table name [duplicate]

≡放荡痞女 提交于 2019-12-24 08:11:34
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: how do find the number of rows in a table when the table name is in a variable? I need to find tables in a SQL Server database (2000) that contain one value for a column. I can use the following query to output a list of possible candidate tables containing my_column : SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'my_column' What I would like to get at, is the following pseudo

Get distinct max date using SQL

馋奶兔 提交于 2019-12-24 07:07:22
问题 I'm not sure quite how to title my question but this is what I'm trying to do: Given pc_tmppl_tbl pc_tmppl_attach pc_tmppl_val1 pc_tmppl_crtdt AJC05-06 AJCINT 2005-08-15 10:32:03.790 AJC06-07 AJCINT 2006-10-17 10:02:06.570 AJC07-08 AJCINT 2007-06-13 10:44:53.573 AJC08-09 AJCINT 2008-06-27 09:51:17.290 AJC09-10 AJCINT 2009-07-20 14:26:06.270 AJC10-11 AJCINT 2010-08-26 11:54:32.777 AJC99-001 AJCINT 2005-05-30 19:30:51.623 ALPI05-06 ALPINE 2005-05-30 19:30:51.623 ALPI07-08 ALPINE 2006-12-11 13

LINQ to SQL Server 2000: “Must declare variable '@p0'”

不羁的心 提交于 2019-12-24 04:27:07
问题 I've created this simple LINQ query: var result = from invoice in invoiceTable where invoice.Id == 1 select invoice.Document; It generates this SQL: SELECT [t0].[Document] FROM [Invoice] AS [t0] WHERE [t0].[Id] = @p0 Whenever I run it though I get this error: (ODBC) ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@p0'. (OleDb) Must declare the variable '@p0'. I remember reading that OleDb and ADO.NET does not support named parameters on SQL Server 2000.

How to update a text or ntext field in SQL Server 2000

你。 提交于 2019-12-24 02:00:36
问题 So I need to update a text field. Neither the UPDATE statement or the WRITETEXT statement work when used below CREATE TABLE MyTable (IDField int, MyField text) INSERT INTO MyTable (IDField) SELECT 1 DECLARE @Data1 varchar(8000), @Data2 varchar(8000), @ptrval binary(16) SELECT @Data1 = REPLICATE('1',8000) SELECT @Data2 = REPLICATE('2',8000) -- this sets MyField to string of only 8000 characters UPDATE MyTable SET MyField = @Data1 + @Data2 WHERE IDField = 1 SELECT @ptrval = TEXTPTR(MyField )

In T-SQL, how to reference to table variable in the subquery?

假如想象 提交于 2019-12-24 00:34:46
问题 I've declared a table variable '@t', and have correctly performed the 'INSERT-INTO-SELECT'. When I was trying to query the table variable with some additional computation for per-group row numbering, I got error either "Must declare the variable" when using '@t' directly or "invalid object name" while using alias of '@t'. Please kindly advise. SELECT *, (SELECT COUNT(*) FROM "LTV" "COUNTER" WHERE "COUNTER"."Collateral_ID" = "LTV"."Collateral_ID" AND "COUNTER"."m_il_no" = "LTV"."m_il_no" AND

Selecting distinct, non-null, unless null is the only value for that record combination (tsql)

送分小仙女□ 提交于 2019-12-24 00:32:56
问题 I have a table with Student ID, Service, and Provider. I want to show the DISTINCT Providers for each Service, but ONLY show NULL Providers if there is no other Provider for that Service and ID. In other words, if a Student has a certain Provider and Service, I don't want to select where the Provider is NULL, unless that specific Student and Provider do not have another non-NULL Provider, in which case I DO want to select the NULL Provider row. I also don't want duplicates for the non-NULLS.

Copy one database to another database

匆匆过客 提交于 2019-12-23 22:36:31
问题 How to copy from one database to another database. Database name visco I want to copy all the table from visco database to new database name as neptune I was created one database with out any tables, then i try to restore the database from database1.bak file, then it is showing error as You are attempting to overwrite an existing database. Check the force restore over existing database option to overwrite the existing database. Need Query Help 回答1: Using the SQL Server Management Studio:

Efficient SQL 2000 Query for Selecting Preferred Candy

南楼画角 提交于 2019-12-23 21:19:36
问题 (I wish I could have come up with a more descriptive title... suggest one or edit this post if you can name the type of query I'm asking about) Database: SQL Server 2000 Sample Data (assume 500,000 rows): Name Candy PreferenceFactor Jim Chocolate 1.0 Brad Lemon Drop .9 Brad Chocolate .1 Chris Chocolate .5 Chris Candy Cane .5 499,995 more rows... Note that the number of rows with a given 'Name' is unbounded. Desired Query Results: Jim Chocolate 1.0 Brad Lemon Drop .9 Chris Chocolate .5 ~250

SQL Server update query not working, however, SQL says the rows were affected

主宰稳场 提交于 2019-12-23 16:11:31
问题 I have a SQL Server 2000 database with a table named Voters . One column in the table ( PrecinctCode of type varchar(10) ) is supposed to have a 4 digit code similar to A111 or D109 , but some rows have a value of '999' . The rows with value '999' have the correct number in a different column ( FaultCode of type varchar(50) ). I want to copy the values from FaultCode to PrecinctCode when PrecinctCode = 999 . I ran this query UPDATE Voters SET PrecinctCode = FaultCode WHERE (PrecinctCode =

Correlated query: select where condition not max(condition in inner query)

夙愿已清 提交于 2019-12-23 16:09:05
问题 I am trying to select all the rows where the userName and groupId is duplicated, and the userId is not the max userId for that userName/groupId combination. Here is my code so far: select * from userTable u where exists (select * from userTable u1 where userName <> '' and userName is not null and u.userName = u1.userName and u.groupId = u1.groupId and u.userId <> max(u1.userId) group by userName, groupId having count(*) > 1) order by userName However, the line: and u.userId <> u1.max(userId)