TVF를 변수에 실행하기
이번 장 앞부분에서 만든 테이블 값 함수 SumStationStats를 기억하시나요? 이 함수는 datetime 매개변수를 받아, 시작일이 입력값과 일치하는 각 출발 역에 대해 탑승 횟수와 총 탑승 시간을 반환해요. 이제 SumStationStats를 실행하고 결과를 테이블 변수에 저장해 보세요.
이 연습은 강의의 일부입니다
SQL Server에서 함수와 저장 프로시저 작성하기
연습 안내
StartStation,RideCount,TotalDuration열을 가진@StationStats라는 테이블 변수를 만드세요.SumStationStats함수를 실행하고 입력 매개변수로'3/15/2018'을(를) 전달하세요.- 함수의 결과를 사용해
INSERT INTO로@StationStats테이블 변수를 채우세요. - 테이블 변수에서 모든 레코드를 선택하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- Create @StationStats
___ ___ ___(
StartStation nvarchar(100),
RideCount int,
TotalDuration numeric)
-- Populate @StationStats with the results of the function
___ ___ ___
SELECT TOP 10 *
-- Execute SumStationStats with 3/15/2018
FROM dbo.___('3/15/2018')
ORDER BY RideCount DESC
-- Select all the records from @StationStats
___ *
___ ___