Below is an example of the BCP Statement. I’m not accustomed to using BCP so your help and candor is greatly appreciated I am using it with a format file as well. If I execute from CMD prompt it works fine but from SQL I get the error. The BCP statement is all on one line and the SQL Server
Tag: sql-server
Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column
I’m trying to insert a large CSV file (several gigs) into SQL Server, but once I go through the Import Wizard and finally try to import the file I get the following error report: Executing (Error) Messages Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column “…
Insert distinct values from one table into another table
So for each distinct value in a column of one table I want to insert that unique value into a row of another table. Any ideas as to how to go about this? Answer Whenever you think about doing something in a loop, step back, and think again. SQL is optimized to work with sets. You can do this using
how to convert date to a format `mm/dd/yyyy`
I’m having a sql table with date column named CREATED_TS which holds the dates in different format eg. as shown below Now I want to convert these to format mmddyyyy before as i am comparing the dates in WHERE clause of my SELECT query. I tried using but got the result as, I need the result as eg. 02/20/…
sql server single row multiple columns into one column
I have table like this From this I need to create a temp table or table like this: Is there a way I can do this in SQL Server? Answer Check this Fiddle If you do want NULL values in the rest, you may try the following: This is the new Fiddle And here is the code:
Membership stored procedure aspnet_Membership_CreateUser not working
I have been trying to make the build in stored procedure to work with Register.aspx. I’m not using the wizard part. Hence writing my own code. I don’t understand where the error is. If I use exec stored procedure and send the same value it will execute in Management Studio. But in code it fails. H…
Sql Command Not Working
I wrote the following code, but nothing is being inserted into the database. I tried changing the SA password in the connection string to something incorrect and the code isn’t catching the exception. What am I doing wrong? Answer As stated by the OP in the comments. Once the try-catch was resolved it w…
Count of non-null columns in each row
I have a table that contains 4 columns and in the 5th column I want to store the count of how many non-null columns there are out of the previous 4. For example: Where X is any value: Answer
Test for Upper Case – T-Sql
All, How can I check if a specified varchar character or entire string is upper case in T-Sql? Ideally I’d like to write a function to test if a character is upper case, then I can later apply that to a generic varchar. It should return false for non alphabetic characters. I am only interested in englis…
Fastest way to determine if record exists
As the title suggests… I’m trying to figure out the fastest way with the least overhead to determine if a record exists in a table or not. Sample query: Say the ? is swapped with ‘TB100’… both the first and second queries will return the exact same result (say… 1 for this c…