sql-server-2005

Different ways to generate the latest int type primary foreign key in code

流过昼夜 提交于 2019-12-13 04:33:12
问题 I am new to sql. I have added 2 new tables in database. The primary key of first is a foreign key in the other. The type of the keys is integer. Now I want to generate the keys in the code and assign it to new data so that the association between different rows of the tables is right. How do I ensure uniqueness of keys and also get the latest key from the db so that there are no errors while saving. If I had used guids then I would have assigned a new guid to the primary key and then assigned

sql server 2005 'update from' query

拈花ヽ惹草 提交于 2019-12-13 04:25:25
问题 I'm trying to update a table based upon the user id from another table. I've come across the Update from syntax but I'm struggling to write my query correctly. The below code should show you what I'm attempting to do. When i run it i get 0 rows affected. update jared_test set user_count = 1 from new_user nuj inner join (select us.userID from users us where us.email = 'j@j.co.uk') u on nuj.userid = u.userid / * ** * ** * * EDIT * ** * ** * ** * ** * ** * ** * \ I discovered there was a problem

Sql query to split one column into two columns

北慕城南 提交于 2019-12-13 04:23:13
问题 I have one single column as project name, the data in project name 1.1.1 chapter1 1.1.2 chapter2 I want to divide that single column into two columns as Major Minor 1.1 .1 chapter1 1.1 .2 chapter2 the datatype of my project name column is nvarchar, I am using sql 2005 Any help? 回答1: Something like this declare @x nvarchar(500) = '1.1.1 chapter1' select substring(@x,1,charindex('.',@x,1+charindex('.',@x))-1) as Major, substring(@x,charindex('.',@x,1+charindex('.',@x)),len(@x)-charindex('.',@x

Creating new date field dynamically from next row

人盡茶涼 提交于 2019-12-13 04:22:15
问题 I have a table of data. I have a field which shows date. I had set this column as Start Date. I want to create an additional column as End Date, where the End Date will be the Start Date of the next row. Can you give me a query of creating the End Date by taking the data of the Start Date in next row ? 回答1: Assuming you already have your columns and that you have an Auto-Incrementing Primary Key: Update T1 Set T1.EndDate = T2.StartDate From [Table] T1 Inner Join [Table] T2 on T1.Id = T2.Id -

SQL injection in Visual Basic 2010

给你一囗甜甜゛ 提交于 2019-12-13 04:17:37
问题 I don't know how to avoid SQL injection, could someone help me with my problem? Here is my current code: Private Function INSERT() As String Dim SQLcon As New SqlConnection Dim SQLdr As SqlDataReader Try SQLcon.ConnectionString = "Data Source=#####;Initial Catalog=OJT;Persist Security Info=True;User ID=####;Password=#####" Dim SQLcmd As New SqlCommand("INSERT INTO dbo.Patients(pIDNo,pLName,pFName,pMI,pSex,pStatus,pTelNo,pDocID,pAddr,pStreet,pBarangay,pCity,pProvince,pLNameKIN,pFNameKIN,pMIKIN

LIKE using subquery returning multiple rows

巧了我就是萌 提交于 2019-12-13 04:13:48
问题 There 2 tables emailinfo(id,email) and keywordinfo(id,keyword). emailinfo contains 80,000 rows and keywordinfo contains 2000 rows. I want emails from emailinfo table which does not contains keywords from keywordinfo table. I want not like condition on multiple rows I have kept all keywords in keywordinfo table Now I have to fetch all the emails from emailinfo table which not containing any keywords from keywordinfo table. I want query like following, select email from emailinfo where email

SQL Query Help after 13th row Dynamic and in 12th row static values with a formula

浪尽此生 提交于 2019-12-13 03:59:18
问题 I have below table structure with the similar to below output. S_NO_ T_P O_P H_P L_P C_P SC_12 1 1 509.75 515 508 512.4500122 2 2 511.7000122 511.7000122 506.1499939 506.5499878 3 4 507.1499939 510.25 507.1499939 510.25 4 5 510 512.3499756 509.2999878 512.3499756 5 3 512.5 512.5 511.1499939 512 6 8 512.25 512.5 510.1000061 510.9500122 7 1 510.5499878 511.7999878 510 511.7999878 8 2 511.1000061 511.8500061 508.1499939 508.8999939 9 5 508.8999939 510 508.5 509.9500122 10 6 509.8999939 509

Pulling .NET Dynamic Data by First Letter only

一世执手 提交于 2019-12-13 03:56:40
问题 I have a long list of dynamic data being generated on a jquery mobile site. I'd like to have this data be separated by alphabet list bars, much like the directory organization of a phone by first letter. Another option would simply be to only call the data by first letter. For example, I select the letter "A", and all the data that starts with "A" displays. I am calling names via ASP.NET.vb repeated method with: <%# Eval("Name")%> That code of course pulls all names. How can I narrow it down

SQL query to display db data

僤鯓⒐⒋嵵緔 提交于 2019-12-13 03:56:13
问题 I have the following database table: Answer MemberID | QuestionNo | AnswerNo | AnswerString 10 | 1 | 2 | q1 anwer2 10 | 2.1 | 3 | q2.1 answer3 10 | 2.2 | 5 | q2.2 answer5 10 | 7 | 1 | q7 answer 7 11 | 1 | 3 | q1 anwer 3 11 | 3 | 1 | q3 answer 1 11 | 5 | 4 | q5 anwer 4 Each member answers different set of questions based on the answers of previous questions. I want to show the answer in the following format MemberID | 1 | 2.1 | 2.2 | 3 | 5 | 7 10 | 2 | 3 | 5 |NULL |NULL| 1 11 | 3 |NULL |NULL |

Convert Legacy SQL Outer JOIN *=, =* to ANSI

十年热恋 提交于 2019-12-13 03:49:16
问题 I need to convert a legacy SQL outer Join to ANSI. The reason for that being, we're upgrading from a legacy DB instance (2000/5 ?) to SQL 2016. Legacy SQL query :- SELECT --My Data to Select-- FROM counterparty_alias ca1, counterparty_alias ca2, counterparty cp, party p WHERE cp.code *= ca1.counterparty_code AND ca1.alias = 'Party1' AND cp.code *= ca2.counterparty_code AND ca2.alias = 'Party2' AND cp.code *= p.child_code AND cp.category in ('CAT1','CAT2') Here, Party1 and Party2 Are the party