I have a column called MealType (VARCHAR) in my table with a CHECK constraint for {“Veg”, “NonVeg”, “Vegan”} That’ll take care of insertion. I’d like to display these options for selection, but I couldn’t figure out the SQL query to find out the constraint…
Tag: sql
Unable to open BCP host data-file
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
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/…
Temp sequence in postgres view
I have a table that I order a certain way often. That ordering is the basis of a derived column we can call rank. If I query the entire table, I can have the database calculate that rank for me: This yields useful results like: With that result set I can determine the rank of any foo. However this requires
Command.ExecuteScalar always return null while Stored Procedure in Management Studio runs fine
I have the following SQL stored procedure with one input parameter and one out parameter. CREATE PROCEDURE [dbo].[spCanUserEdit] ( @username nvarchar(255) ) AS BEGIN SET NOCOUNT ON; DECLARE @CanEdit …
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…
How to run OPTIMIZE TABLE with the least downtime
I have a MySQL 5.5 DB of +-40GB on a 64GB RAM machine in a production environment. All tables are InnoDB. There is also a slave running as a backup. One table – the most important one – grew to 150M rows, inserting and deleting became slow. To speed up inserting and deleting I deleted half of the …