Storing files in SQL Server database

I want to store files in my SQL Server database by C# which I have done it without problem. This is my code: byte[] file; using (var stream = new FileStream(letter.FilePath, FileMode.Open, FileAccess.Read)) { using (var reader = new BinaryReader(stream)) { file = reader.ReadBytes((int)stream.Length); letter.ltr_Image = file; } } LetterDB letterDB = new LetterDB(); id […]

Return distinct column1s data when every row for column2 is null

I am attempting to return a distinct listing of column 1’s “table_ID” when column 2 is “only” null in “DATA_TABLE”. Table_ID | Value 1 | null 2 | 55 1 | null 3 | 5 3 | null So, in this query – I would only wish to return Table_ID of 1, 2 has no […]

invalid parameter 1 specified for datadiff

I want to update field everyday automatically in database about duration. the formula is (due date – date now). I want to use sql server agent. But when I test the job its failed. USE FacilityMonitoring GO UPDATE [dbo].[klaim] SET selisihint = DATEDIFF (“dd”, GETDATE(), durasi_end) GO Query in SQL Server agent: Error:

Alternate query for cross apply in SQL Server 2005

Query: SELECT DISTINCT CREATEDBY, PITCHES, [COUNT], REVENUE, ORD FROM @TEMPMAILER CROSS APPLY (VALUES (‘Total Active’, CNTACTIVE, TOTALREVACT, 0), (‘In Suspect’, CNTSUSPECT, TOTALREVS, 1), (‘In Prospect’, CNTPROSPECT, TOTALREVP, 2), (‘In Approach’, CNTAPPROACH, TOTALREVA, 3), (‘In Negotiation’, CNTNEGO, TOTALREVN, 4), (‘In Closure’, CNTCLOSURE, TOTALREVC, 5), (‘In Order’, CNTORDER, TOTALREVO, 6)) V (PITCHES,[COUNT], REVENUE, ORD) I want data […]

String manipulation in SQL

I’m using SQL server 2014.I have a column that has text data in it. The data would look like this: create table #temp ( stringdata varchar(100) NULL ) insert into #temp values (‘CN=ABCD,PN=XYZ,AD=123,AN=rst’), (‘AN=ABC,PN=XYZ,CN=12,AN=rst’), (‘AN=ABC,CN=XYZ,PN=123,AN=rst’), (‘AN=ABC,AN=XYZ,CN=1234567,PN=rst’) And I need the result set value that is mapped for CN. I tried to extract the data with […]

SQL Server UDF SQLCLR Call Converts Characters Into Question Marks

I’ve found nothing on Google or SO that quites lines up with my issue. In SQL Server, I have a scalar function (we’ll call it dbo.MySqlStringFunction). What this function does is call a utility written in C# that calls an ASP.Net view and returns the HTML as a SqlString. The function definition in SQL Server […]

Check if data exists in SQL Server

I’m trying to create a checking from my table. I have three tables hari , transaksi & Outlet. My table hari has only one column called days: days 2016-07-21 00:00:00.000 2016-07-22 00:00:00.000 2016-07-23 00:00:00.000 2016-07-24 00:00:00.000 2016-07-25 00:00:00.000 2016-07-26 00:00:00.000 My second table is transaksi: | outlet | Tanggal | K-MGAS 2016-07-23 K-JGMM2 2016-07-24 K-JGMM2 […]

Alter Table 'DEFAULT' not setting default values – SQL Server

I am trying to alter an existing column and adding an integer column. While adding integer column i am setting DEFAULT as 10 but default is not setting while adding the column ALTER TABLE dbo.Contacts ADD Col1 INT DEFAULT 10 I require to do explicit update script to set all past records as default values […]

Connecting to SQL Server Database using a Hosted Web Application

I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. I have tested it using my localhost and it works fine. Now I would like to publish this application on a hosted site. My question is, does the database need to be on the same […]

Unsure why this query is inserting duplicate records

I have a table Customers which has the PK CustomerID and two date fields TransDate and UpdatedDate. I have another table PaymentPlan which has three date fields: StartDate, EndDate and UpdatedDate. I need to find all Customer records that meet the following criteria and then insert them into another table. TransDate is not null and […]

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