I don't know what is wrong with this code

I don’t know what is wrong with this code, but it just jumps to the else part. Can you please help me out? SqlCommand cmd = new SqlCommand(“select * from TB_VH_HW where UserName='” + Txtusername.Text + “‘ and Password='” + txtpassword.Text + “‘”, con); con.Open(); int i = (int)cmd.ExecuteScalar(); if (i == 1) Server.Transfer(“userlogin.aspx”); else […]

Incorrect syntax near the keyword 'USE' error while creating database from Script

I am developing a multi tenant application so I need to create database from code for every new client. I have generated script of my schema from SSMS “Generate Script” utility, then I tried the following: public static void CreateIfNotExist(string path) // the path where the script for creating database is located { var db […]

Two values on same variable

I’m trying to update a table using C# and I am able to do that. I am deserlizing a XML-file and then updating a table with those values from the XML. This works. However, sometimes the primary key is replaced with another value. For example: I want to update Name, LastName, Middlename where PersonIdentity = […]

Delete duplicate records from SQL Server where all values are the same except primary key

My table contains more than 10 columns. For example: id name date status rec_id ….. etc ——————————————————- 1 ssss 01/01/2000 Active 3 ….. 2 ssss 01/01/2000 Active 3 ….. 3 aaaa 11/01/2002 Active 5 ….. 4 aaaa 11/01/2002 Active 5 ….. I want to delete duplicate records in this table and I want results like […]

Get Value from another column but same row in SQL

I have a sql database that is setup like this: +——+——+ |code |used | +——+——+ |1021 |0 | +——+——+ |2235 |0 | +——+——+ |3324 |0 | +——+——+ |1914 |1 | +——+——+ |2215 |1 | +——+——+ I am wondering what statement can I run in Java code, so that I get the find the row that […]

Replace empty values as 0 instead of null while joining two tables in sql

I have join two tables t1 and t2. The output produces some null records since there is no data in the table t2. Instead of showing null I want to show 0 since I have to perform some arithmetic operation in the crystal reports. please help me…..

SQL get values for only a few hours in given time period?

My first question here..! I’m not an expert in SQL, so bear over with me please! 🙂 I have a web page (not created by me) which gets report data from a MSSQL database, on the web page you enter start date and end date and data are fetched in this time interval from 00:00 […]

Gaps and Islands query / reset row count based on column seqeunce

I know there are many examples of this, but still can’t find the exact solution. I am looking to reset a row count based on sequences of 1s and 0s. DECLARE @TestTable TABLE (category INT, ts INT,window int) INSERT INTO @TestTable (category,ts,window) VALUES (1,1,1),(1,2,1),(1,3,0),(1,4,0),(1,5,1),(1,6,1),(1,7,1),(2,1,0),(2,2,1),(2,3,1),(2,4,1),(2,5,0),(2,6,0),(2,7,1),(2,8,1),(2,9,1),(2,10,1),(2,11,1) In the table above, I want a row number column that […]

C# – Load data into SQL Server and merge if already present

Suppose I have the following table in SQL Server: MyTable: IDCol: Val1: Val2: 1 a b 2 c d … And, I am only able to access / modify it via direct SQL statements (meaning I can’t put a file in a location and tell it to upload that file, for example) So, currently, in […]

Writing my result as horizontal as String

Can someone help me how I can rewrite this query to get following result. 1 2 3 4 5 U.T A.H E.Z R.Z S.A Sometimes it will return more or less than 5 results. My query: SELECT LEFT(a.Vorname, 1) + ‘.’ + LEFT(a.Name, 1) AS Name FROM ADR_Adressen a LEFT JOIN ADR_GruppenLink gl ON gl.AdressNrADR […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.