[Solved] Custom hierarchy

Here is a generic method regardless of the level of the hierarchy. SQL — DDL and sample data population, start DECLARE @tbl table ( idGeo INT IDENTITY PRIMARY KEY, GEO VARCHAR(64), PARENTID INT ); insert into @tbl (GEO, PARENTID) values ( ‘EMEA’, NULL), ( ‘France’, 1), ( ‘mIDCAPSfRANCE’, 2), ( ‘Germany’, 1), ( ‘France exl … Read more

[Solved] Insert an image in a column of a table that already has 5 columns

I’m not sure you can do that the way you’re trying, Why don’t you load the image into a variable then use that variable in your insert statement: declare @image varbinary(max) set @image = (SELECT BulkColumn from Openrowset( Bulk ‘C:\Users\Yassine-Kira\Desktop\Templates\ProductImg\elite-book_tcm_133_1096796.png’, Single_Blob) as BikeImage) insert into dbo.Produit values (‘Pc portable’, ‘HP EliteBook série p’, ‘Un ordinateur…’, … Read more

[Solved] Joining two SQL tables in Microsoft SQL server 2012 to get a certain format [closed]

After re-reading your question, I think this is what you are looking for: SELECT e.Department_ID , e.Employee_Name AS Col1 , e.Total_Hours FROM Employee e UNION ALL SELECT d.Department_ID , d.Department_Name AS Col1 , SUM(e.Total_Hours) FROM Employee e JOIN Department d ON e.Department_ID = d.Department_ID GROUP BY d.Department_ID , d.Department_Name ORDER BY Department_ID ASC , Total_Hours … Read more

[Solved] Execute query using C# [closed]

SqlCommand has ExecuteReader, for executing the command and returning a dataset, ExecuteScalar for returning a single value of a primitive type (int, string, etc.), or executeNonQuery for returning nothing. You can also pass a command to a SqlDataAdapter, and use that to populate a DataTable object. Please google SqlCommand and you will find LOTS of … Read more

[Solved] SQL db and Combobox [closed]

So here we go. I will help you with such task. First get list of databases. Then get list of tables (parameter is Connection string, where you should add the name of the database you have choosen in your combobox. public List<string> GetDatabaseList() { List<string> list = new List<string>(); string conString = “Data Source=yourDataSource; Integrated … Read more

[Solved] how to get sum(col2) as somename,(col2*col3)/Sum(col2) as somename1 for the some date

You can achieve what you’re after like below: CREATE TABLE SampleTable ([col1] varchar(1), [col2] int, [col3] int, [date] varchar(16)) ; INSERT INTO SampleTable ([col1], [col2], [col3], [date]) VALUES (‘a’, 11, 0, ‘3/6/2015:0:00:00’), (‘b’, 5, 4, ‘3/6/2015:0:00:00’), (‘c’, 5, 5, ‘3/6/2015:0:00:00’), (‘d’, 3, 0, ‘3/6/2015:0:00:00’), (‘e’, 21, 21, ‘3/6/2015:0:00:00’) ; SELECT t2.SumCol2, sum(t1.col2 * t1.col3) / … Read more

[Solved] difficulty giving aliases inside case statement

Use: Count(case when a.photoappimage is null then 1 end) as via_u, Count(case when a.photoappimage is null then 1 end)/100. as via_u_pct, Count(case when a.photoappimage=1 then 1 end ) as via_p, Count(case when a.photoAppImage is null or a.photoAppImage=1 then 1 end) as via_u_or_p Update: combining all (and use a subquery to simplify pct calculation): select storeId, … Read more