sql-server-2000

How i can get the first 3 digits in 123456 Numbers in sql?

ぃ、小莉子 提交于 2019-12-05 03:25:58
I have field called CallingParty in My CDR table it contains data like this CallingParty 267672668788 I want to select the first 3 number of each of those numbers like CallingParty 267 if CallingParty is of type int: SELECT CAST(LEFT(CallingParty, 3) AS INT) From CDR SQL Server has a Left() function, but it works best on strings. (varchar/char in SQL) Select left(cast(267672668788 as varchar), 3) Nick Use this query: SELECT SUBSTRING(CAST(CallingParty AS VARCHAR(50)), 1, 3) FROM [CDR] If the data length does not change then you can always divide by 10 * the digits you have SELECT FLOOR

How do I script SQL constraint for a number to fall within a range?

送分小仙女□ 提交于 2019-12-05 03:09:08
Using SQL Server, how do I script a constraint on a field in a table, so that the acceptable range of values is between 0 and 100? ALTER TABLE Table ADD CONSTRAINT CK_Table_Column_Range CHECK ( Column >= 0 AND Column <= 100 --Inclusive ) A check constraint like "fieldname BETWEEN 0 AND 100" should do it. Try: ALTER TABLE myTableName ADD CONSTRAINT myTableName_myColumnName_valZeroToOneHundred CHECK (myColumnName BETWEEN 0 AND 100) This check would be inclusive - here is some info about BETWEEN from MSDN: BETWEEN (Transact SQL) According to me, the right question isn't "how" but "why". This 0

Why does the order of join clauses affect the query plan in SQL Server?

自作多情 提交于 2019-12-05 00:55:20
I am building a view in SQL Server 2000 (and 2005) and I've noticed that the order of the join statements greatly affects the execution plan and speed of the query. select sr.WTSASessionRangeID, -- bunch of other columns from WTSAVW_UserSessionRange us inner join WTSA_SessionRange sr on sr.WTSASessionRangeID = us.WTSASessionRangeID left outer join WTSA_SessionRangeTutor srt on srt.WTSASessionRangeID = sr.WTSASessionRangeID left outer join WTSA_SessionRangeClass src on src.WTSASessionRangeID = sr.WTSASessionRangeID left outer join WTSA_SessionRangeStream srs on srs.WTSASessionRangeID = sr

How to write a recursive query in SQL Server 2000

柔情痞子 提交于 2019-12-04 23:17:58
I have a table which has a list which looks like this References R. Name LineNo. References A 1.1 (B,24.1) A 6.3 (A, 1.3), (D, 22.1) B 23.1 (A. 1.2) B 24.1 (B,23.1) C 2 (A, 1.1) D 3.12 (A, 6.3) The query should go one by one in the records and generate a value based on the references, pick first one lets say, which is Report Name A, Line No. 1.1, Now the reference is (B, 24.1), which means we need to find Report Name B, line no 24.1 and pick its value. In the same table R.Name B and Line No B, 24.1 is referenced by (B, 23.1), So now we need to find Report name B, Line No 23.1, We go on through

What happened with SQL English query?

我的未来我决定 提交于 2019-12-04 23:12:44
SQL Server 2000 was deployed with English Query. At that time, I was young and new to SQL so I skipped that chapter. Now after years, there is again an idea of making a logical program which can understand simple user questions. Is there any alternative to that? Where is English Query now? Though it's not the same thing, Full Text Search is the closest thing to "English Query" that exists in SQL 2005+. English Query was discontinued after SQL Server 2000. English query not part of SQL Server since version 2005 English Query is unfortunately not available in Microsoft SQL Server 2005. You can,

Validate telephone number in SQL Server 2000

只愿长相守 提交于 2019-12-04 22:52:43
Does anyone have a nifty way of validating telephone numbers using sql (SQL Server 2000). I need to select all users fro ma Db that have valid phone number Thanks Sp Valid number 08450000000 01332000000 07444000000 +441332000000 Standard UK numbers If you have a regular expression to match the number, you can install a regex extended stored procedure on your SQL Server. I installed this extended stored procedure at work and we use it quite a bit. There are several procedures (each with corresponding function wrappers): check for matches (yes, no) check for matches (count) search and replace

How do I limit a LEFT JOIN to the 1st result in SQL Server?

我与影子孤独终老i 提交于 2019-12-04 22:28:42
I have a bit of SQL that is almost doing what I want it to do. I'm working with three tables, a Users, UserPhoneNumbers and UserPhoneNumberTypes. I'm trying to get a list of users with their phone numbers for an export. The database itself is old and has some integrity issues. My issue is that there should only ever be 1 type of each phone number in the database but thats not the case. When I run this I get multi-line results for each person if they contain, for example, two "Home" numbers. How can I modify the SQL to take the first phone number listed and ignore the remaining numbers? I'm in

Getting age in years in a SQL query

依然范特西╮ 提交于 2019-12-04 21:18:39
Hello I've been tasked with doing a few queries on a large SQL Server 2000 database. The query I'm having trouble with is "find the number of people between ages 20 and 40" How would I do this? My previous query to get a count of everyone looks like this: select count(rid) from people where ... (with the ... being irrelevant conditions). I've googled some but the only thing I've found for calculating age is so large that I don't see how to embed it into a query, or it is a stored procedure which I do not have the permissions to create. Can someone help me with this? The relevant part of the

SQL Server 2000/2005 identity column + replication

爱⌒轻易说出口 提交于 2019-12-04 19:42:50
I have looked at some resources already and just want to clarify and get an opinion. First of all to totally avoid any problems we could just not bother using identity columns as primary keys instead have them generated ourselves and just have those values replicated both ways presuming they are always unique at any time of creation. For the purposes of this question I am talking about 2 or more way replication to solve global access issues and we do have identity columns. Now we are setting up transactional replication and both databases should replicate to each other. As I understand it you

The log file for database is full

孤人 提交于 2019-12-04 19:32:50
问题 So our SQL Server 2000 is giving me the error, "The log file for database is full. Back up the transaction log for the database to free up some log space." How do I go about fixing this without deleting the log like some other sites have mentioned? Additional Info: Enable AutoGrowth is enabled growing by 10% and is restricted to 40MB. 回答1: Scott, as you guessed: truncating the log is a bad move if you care about your data. The following, free, videos will help you see exactly what's going on