Loading...

Follow Reddit - SQL (Structured Query Language) on Feedspot

Continue with Google
Continue with Facebook
or

Valid

I have to write a piece of code to be able to speak information to alexa and have it automate the data into creating a entry on a website that already has data. For example. "Alexa set name 'John Smith' set age '27' set address '333 Tree Street'" and have a piece of data come out on the website as "John Smith, 27, 333 Tree Smith". As someone who's knowledge is limited to aggregate functions, manipulation, and queries (the basics I know) how could I go about doing this. I have a 6-month deadline.

''

submitted by /u/sqljobaccount
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

How does querying databases in a business environment work? In my school program we query databases but they are all small databases with few tables. If anybody could clarify how you know what to query in database for a business setting, where I'm sure there are possibly hundreds of tables connected, it would be nice to know (Do you look up the ERD or what?). Thanks!

submitted by /u/mdwolfe123
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I'm hoping someone can help me understand why this works:

DECLARE @cols NVARCHAR(MAX), @query NVARCHAR(MAX); SET @cols = STUFF( ( SELECT DISTINCT ','+QUOTENAME(c.[CellName]) FROM [dbo].[CellsActive] c FOR XML PATH(''), TYPE ).value('.', 'nvarchar(max)'), 1, 1, ''); SET @query = 'SELECT [Week] as [Week],'+@cols+'from (SELECT [Week], [Qty Remaining] AS [amount], [CellName] AS [category] FROM [dbo].[CellCapacityUnionByWeek] )x pivot (max(amount) for category in ('+@cols+')) p'; EXECUTE (@query); 

But this doesn't:

SELECT [Week] as [Week],STUFF( ( SELECT DISTINCT ','+QUOTENAME(c.[CellName]) FROM [dbo].[CellsActive] c FOR XML PATH(''), TYPE ).value('.', 'nvarchar(max)'), 1, 1, '') from (SELECT [Week], [Qty Remaining] AS [amount], [CellName] AS [category] FROM [dbo].[CellCapacityUnionByWeek] )x pivot (max(amount) for category in (STUFF( ( SELECT DISTINCT ','+QUOTENAME(c.[CellName]) FROM [dbo].[CellsActive] c FOR XML PATH(''), TYPE ).value('.', 'nvarchar(max)'), 1, 1, ''))) p 

Trying to execute the latter returns an error for the second 'stuff' statement

Now you are probably wondering why I'm trying to not use variables, I want to create a view from the data returned (the third party app I am connecting to the server with does not offer the option to call SPs, only views and tables) and it's my understanding I can't create a view from a script with variables.

Open to any suggestions on how to return the data to a view or table. It seems the way to go may be to use a table-valued functions but I am also having trouble understanding how to convert this script into a table-valued function.

submitted by /u/ParanoidLoyd
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Sample Data

Hi /r/SQL! Via a series of subqueries, I have a table with results as seen in the attached screenshot.

Out of that set of results, I need to draw additional information out.

I need to determine the number of InvoiceIDs (column a) that appear only once AND are "matched" with an OrderID (column b) that also appears only once in its respective column.

I hope this is explained well enough. Please let me know if you need further clarification.

Thanks!

submitted by /u/the_toaster_lied
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have some data in one column that is delimited by a greater than (' > ') sign.

Example:

12345 Apple St > Anywhere Town > State > Zip

The four values that are delimited, I need to split out into four separate columns named street, city, state and zip in my query.

I am currently working with SQL Server 2012 and this will eventually be used in an SSRS .rdl

I've tried many solutions found via Google but so far, I have not been successful.

I would appreciate any help. Thx.

submitted by /u/Naheka
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Hello,

I have a view with the following data

  • Account Number
  • Product
  • Start Date
  • End Date

and for explanation's sake, say customers can have either Product A, Product B, Product C, or any combination of the three active at any given moment. They can cancel any of these products at any time, and can resume them at any time.

What I want to do is create a flag, called 'standalone_b', that says, "for this customer, for the time this instance of Product B was active in its history, it never had an active Product A". Is there a SQL-92 compliant way to create this?

Thank you for any information you can provide!

submitted by /u/maditab
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The question is, "For each author, return the title and published_date of their first book. The result set should have five columns: author’s id, author’s name, book’s id, book’s title, and book’s published_date. "

So i have

SELECT authors.id, authors.author, books.id, books.title, books.published_date

FROM authors

INNER JOIN books

ON authors.id = books.author_id

So I have the ouput I want except its displaying every book by each author with the required items, how to I get it to only show the book with the earliest published_date?

Thanks in advance.

submitted by /u/mjl2350
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I'm trying to write a code to display 15 days before a particular date. However the date can't be a weekend or holiday. It doesn't need to be 15 business days. Just 15 days before to the nearest business day. This is what I came up with, but it's still choosing weekend dates:

WhileReadingRecords; DateVar Array Holidays := [ Date (2019,1,1), // you can put in as many lines for holidays as you want. Date (2019,1,21), Date (2019,2,18), Date (2019,5,27), Date (2019,7,4), Date (2019,9,2), Date (2019,10,14), Date (2019,11,5), Date (2019,11,11), Date (2019,11,28), Date (2019,12,25)]; Local DateTimevar StartDate:={sv_data_for_crystal.ReviewDate}; //Put your field name in here Local DateTimevar StartDate2:= DateAdd ("d",-15,StartDate); if dayofweek(StartDate2) in 2 to 6 and not (StartDate2 in Holidays) then StartDate2 else DateAdd ("d",-1,StartDate2);

submitted by /u/Stunna2018
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Working in MS SQL Server, I have a table that contains a date column, and another column that contains Number of Days as an integer. What I would like to do is use those two fields to create an end date, but then also generate a new data set with the number of days in each month that the Start Date and generated End Date span across.

To try and help explain further I have created a sample table of the base data, then a screenshot of the new data set I'm trying to generate. Can't seem to wrap my end around how to go about it.

 create table #example_table ( RecordID int ,StartDate date ,NumDays int ) insert into #example_table values (1,'1/15/2019',5) ,(2,'2/17/2019',67) ,(3,'3/4/2019',45) select * ,dateadd(d,NumDays,StartDate) as EndDate from #example_table drop table #example_table 

Desired final data output

RecordID Year Month NumDaysMonth
1 2019 1 5
2 2019 2 11
2 2019 3 31
2 2019 4 25
3 2019 3 27
3 2019 4 18
submitted by /u/wjbaltz
[visit reddit] [comments]
Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Hello, I’m just starting to learn about SQL and have been advised to practice coding with MySQL on a Windows computer. But, I prefer to work on my iPad. Can anyone recommend an iPad version of MySQL?

Thanks

submitted by /u/ghumpoi
[visit reddit] [comments]
Read Full Article

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview