Multi-statement table-valued function with join [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 days ago.
Improve this question
I'm trying to create a function that, when a country name is entered, it returns a table including the country name, country code, currency name and currency code.
create or alter function dbo.CountryCode_and_CurrencyName (#CountryName nvarchar)
returns #CurrencyAndCountry table (
country_name nvarchar(50),
country_code char(2),
currency_name nvarchar(50),
currency_code char(3)
)
as
begin
insert #CurrencyAndCountry
select
ctry.name,
ctry.country_code,
curr.name,
curr.currency_code
from dbo.country ctry
join dbo.currency curr
on curr.currency_code = ctry.primary_currency_code
where ctry.name = #CountryName
return
end
select * from dbo.CountryCode_and_CurrencyName
('United Kingdom')
When I execute this function the fields are returned, but nothing is returned under the fields. I'm guessing that I need to define/match the parameters with the table fields. Can anyone help me out? Thanks in advance.

Related

Issue with "group by" and "having" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
HAVING COUNT(DateOfBirth) > 1
GROUP BY DateOfBirth
)
SQL Server 2019 is saying I have a syntax error by "GROUP"
I am trying to find employees who have the same date of birth
As D. Use a GROUP BY clause with a HAVING clause from Microsofts's SELECT - GROUP BY- Transact-SQL shows HAVING comes after GROUP BY:
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
GROUP BY DateOfBirth
HAVING COUNT(DateOfBirth) > 1
)
ORDER BY DateOfBirth -- Optional

How can I extract both column from View named "Max_part_supplied'? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have created a view named 'Max_part_supplied' which consists of two column as
Number_of_parts and Supplier_name.
I am trying to access the Supplier_name who supplies maximum number of parts, as
select MAX(Number_of_parts) as max_part, Supplier_name
from Max_part_supplied;
This is the view Max_part_supplied
Number_of_parts Supplier_name
1 Ambani Traders
3 Lalu Traders
2 Paltu Traders
1 Sunil Traders
But I am getting error message as
Msg 8120,Level 16,State 1,line 84
Column Max_part_supplied.Supplier_name is invalid in the select list because it is not containted
in either aggregate function or the GROUP BY clause.
It looks like your view already has the max per supplier, you just want the maximum of these?
select top (1) Number_of_parts, Supplier_name
from Max_part_supplied
order by Number_of_parts desc
If you want all suppliers in the event two or more have the same max, use top (1) with ties

SQL Server Temp Table to a Select Distinct Count Distinct quetsion [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Ok, basically I've got a lot of temp tables I've created and I'm trying to create Validation for the ProvDiff table.
DROP TABLE #ProvDiff;
IF OBJECT_ID ('temp.dbo.#ProvDiff') IS NOT NULL
DROP TABLE #ProvDiff;
SELECT *
INTO #ProvDiff
FROM
(SELECT DISTINCT *
FROM #finalclaimswithflags f
WHERE f.[Pay-To Prov NPI] <> f.[Rendering Prov NPI]) ProvDiff;
SELECT DISTINCT COUNT(DISTINCT ???) AS 'Unique EI NPIS'
FROM #ProvDiff
In my head it seems like the differences should be able to produce a result and I should be able to do a count on that. But for the life of me I can't figure out how to do that. If I do a count on rendering or pay to then those numbers wouldn't necessarily reflect the value for what are above. I know how many of each are produced for above validation.
Any help would be greatly appreciated
Is this what you want?
SELECT COUNT(*)
FROM (SELECT DISTINCT *
FROM #finalclaimswithflags f
WHERE f.[Pay-To Prov NPI] <> f.[Rendering Prov NPI]
) ProvDiff;
I don't see why a temporary table would be used for this.
For better or worse, SQL Server does not support select count(distinct *), so you pretty much need a subquery.

Multiple WHERE Query to eliminate data? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need help creating a large query to select a subset of data.
I need to filter out certain information before I can do my analysis. First I select any call which reached my programs. Then I need to filter out all of the fake/test calls. Then I need to eliminate the ineligible calls which is dependent on a few factors like if the Owner or Sender column is a specific designation, or if the Creator column is a specific designation ONLY IF the call type is one of two options. It is super complicated for me.. hopefully someone can help.
SELECT * FROM Table1
WHERE CustomerID IN (SELECT CustomerID FROM Table1
WHERE SiteID
IN ('Site1', 'Site2'))
WHERE CustomerID <> (108 different values)
AND OwnerID <> (A)
AND SenderID <> (A)
AND CreatorID <> (A) but ONLY if CallType <> CallType1 or CallType2;
SELECT *
FROM Table1
WHERE CustomerID IN (
SELECT CustomerID
FROM Table1
WHERE SiteID IN ('Site1', 'Site2'))
AND CustomerID not in (108 different values)
AND OwnerID <> (A)
AND SenderID <> (A)
AND not ( CreatorID = (A) and
CallType in ( CallType1, CallType2 ) )

Syntax error in writing a SQL sas code using case when and like statements [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
See code below. For a specific industry e.g. "Fss" there are a list of titles against which the variable job title has to be matched for flag creation.
proc sql;
create table ildp.ildp_1h_v5 as
select industry,jobtitle,webpagesource,assetname,qtr,companyname,
case
when industry = "FSS" and (jobtitle like 'CMO%' OR jobtitle like 'Chief Innovation)
then 1
else case when ..#continued.#
or like is not valid SQL. Try this:
proc sql;
create table ildp.ildp_1h_v3 as
select *,
(case when industry = "FSS" and
(jobtitle like 'CIO%'
OR jobtitle like 'ChiefInnovation%'
OR jobtitle like 'director%'
OR jobtitle like 'head%'
OR jobtitle like 'distribution%'
OR jobtitle like 'claims%'
OR jobtitle like 'VP%'
OR jobtitle like 'President%')
then 1 else 0
end) as title_flag
from ildp.ildp_1h_v2;
quit;