Viewing 15 posts - 406 through 420 (of 4,085 total)
You do realize that the IF and the ELSE section are EXACTLY THE SAME, right? One definition of insanity is doing the same thing and expecting different results.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 7:03 pm
Can't you use RIGHT or SUBSTRING ?
You can use RIGHT() or SUBSTRING(), but both of those tend to be more complex than STUFF().
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 6:52 pm
Hi,
I am doing STUFF in my query which is concatenating the blank data too and data looks like below. Sometimes there is space+comma and sometimes only comma in the...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 6:50 pm
You would use a CROSS APPLY or OUTER APPLY like any other table-valued function.
FROM data.dbo.CalendarEvents AS ce
INNER JOIN data.dbo.ObjectMetadata AS OM2
ON ce.ParentObject = OM2.ObjectID
INNER...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 4:20 pm
Maybe Drew will chime in. He comes up with some great creative SQL solutions.
I would need some data and expected results to work with.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 3:39 pm
Also, get rid of the DISTINCT. UNION already does a distinct, so specifying DISTINCT here just clutters up your code with no benefit.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 19, 2019 at 2:32 pm
Hey Drew,
Which part of the query is static, I am curious?
If you referring to the last query I posted, that's the printed version after I did PRINT @query.
I don't...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 18, 2019 at 8:43 pm
The problem you are seeing is that you made a dynamic part of your query static. Specifically, the 'Year_' + CONVERT(NCHAR(4), YEAR(eventyear)) needs to be dynamic so that when you...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 18, 2019 at 7:55 pm
tjolliffe's approach requires two scans of each of the tables. The following only uses one scan of each of the tables, but you may be better off just skipping the...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 18, 2019 at 7:34 pm
It's embedded. You need to ADD quotes, not take them away
''YEAR_'' + CONVERT(nvarchar(8), YEAR(eventyear)) eventyear,
Before you execute the dynamic SQL, print it.
PRINT @query
Run that query, fix the issues, and...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 18, 2019 at 6:04 pm
DATE/TIME data should be stored in DATE/TIME fields. If they are stored in any other format, you should consider changing that.
DATE/TIME data is not stored in a human-readable format. It...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 17, 2019 at 6:48 pm
T-SQL 2012 has a new built in function to give a running total, so you don't need a cursor for running totals that sum distinct counts. Previously sum...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 16, 2019 at 9:55 pm
Did you really think it was necessary to post 5000 lines of data to illustrate your issue?
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 16, 2019 at 4:15 pm
From your data, I think what you're really dealing with is a overlapping intervals problem. You have overlapping intervals (student start and end dates) and you need a running count...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 16, 2019 at 4:00 pm
This thread is SEVEN YEARS OLD, so it's not safe to make any assumptions about what the OP is currently using.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 16, 2019 at 3:03 pm
Viewing 15 posts - 406 through 420 (of 4,085 total)