Tag: mysql

SQL query using ON or JOIN

I’m sure this can be done with a join but I’m less that clueless when it comes to joins: Say that I have 3 tables. Table one is branches, table 2 is counties and table 3 is states Table one: branchid – Unique record id siteCode – Unique identifier for the branch address1 – Street […]

SQL – How to add a custom text at the beginng of a row

i have a sql query to merge all rows to one. What i try to is to set only a custom at the beginning. My problem is that always repeat it for every new value. How can i fix it? Thanks in advance here is my code: SELECT STUFF ((SELECT ‘Please Select’ + ‘ : […]

Transaction in Stored procedure

Please can someone help. I have several stored procedures in a job, and In one of them I Begin a transaction to delete some rows and if rows are greater than 10 then I Roll back. however if there are not I don’t want to commit straight away, because 2 stored procedure later I do […]

Creating primary key on existing table sql

I have a table of the following form: create table tab1(i1 int, i2 character varying); I want to make i1 as the primary key. However my problem is i1 column contains duplicate rows. In order to achieve this I created a table of the following form: create table tab2(i1 int, i2 character varying); insert into […]

Need help writing an SQL join query

I have a table called “customer_requests”: [CustomerRequestID] [Title] [Description] [RFQDate] [Q2CDate] [QuantityRequested] [GST] [NetCost] [Markup] [NetSellPrice] [GrossSellPrice] [fkCustomerID] [Status] And a table called “job”: [JobID] [JobTitle] [Description] [fkCustomerRequestID] [fkSupplierID] [fkSupplierQuoteID] [Quantity] [Cost] [Status] [ETA] [LoggedBy] [DeliveryAddress] [ParentJobID] I want to write a select query that selects ALL entries from both tables, and displays them in […]

column name for display in case

SELECT favorite_id,MO,name,image_id,case image_id when 0 then (select image_path as image_path from images where image_id in (select default_image from registration where reg_id=9)) else (select image_path as image_path from images where image_id=b.image_id and active=1) end FROM buddies b where reg_id=9 in this select: select image_path as image_path i need to name the column name but because the […]

How to create sequential ID's per user in Postgresql

I’m trying to create a table in postgresql to hold user Work Items. Each Work Item will have a unique ID across the system, but then will also have a friendly sequential ID for that specific user. So far I have been just using: CREATE TABLE WorkItems ( Id SERIAL NOT NULL PRIMARY KEY, … […]

Store connection string in database and retrieve it on application startup

I am developing an winforms application in VS 2010 to retrive data from Sql Server or MySql to Sql Server or MySql. My design is something like this. So here I am storing all values of connection string in Sql Server database table in separate column. I am able to get the required fields and […]

SQL query to join 2 tables

I want to join the following 2 tables in postgres: table1 ( i1 character varying , i2 character varying , i3 character varying ) table2 ( i4 character varying , startorend character varying , begin integer , end character integer ) table1 contains the following values: p1 p2 p3 p4 p10 p6 p7 p8 p9 […]

SQL – Select Boolean Results from Table

Well ,I didn’t find a correct title for this question, sorry about that. I Have one table where I store some emails sent to users. In this table I can know if the user read or not the email. Table structure: [MAILSEND_ID] (INT), [ID_USER] (INT), [MAIL_ID] (INT), [READ] (BIT) Data: ;WITH cte AS ( SELECT […]

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